How to change Lattice graphics default groups colors?

痞子三分冷 提交于 2019-12-08 11:09:30

问题


When using groups, Lattice gives each group a different color. Example:

df <- data.frame(x=1:56, y=rnorm(56), class=1:14) # create some data
xyplot(y ~ x, groups=class, data=df, type="l", auto.key=list(space="right"))

However, by default Lattice only uses seven colors, as running the example above will show. If you have more than seven groups, Lattice cycles through the colors again in order, causing data from distinct groups to have the same color. I learned from another Stackoverflow article that these colors are stored in trellis.par.get()$superpose.symbol$col. I want to make the list of groups colors longer (without having to specify colors explicitly in plotting calls). I can't figure out how to change this list of colors, however. (This might be due to ignorance about some basic facts about Lattice syntax or semantics.) This illustrates the problem:

> trellis.par.get()$superpose.symbol$col
[1] "#0080ff"   "#ff00ff"   "darkgreen" "#ff0000"   "orange"    "#00ff00"   "brown"    
> class(trellis.par.get()$superpose.symbol$col)
[1] "character"
> mycolors <- c(trellis.par.get()$superpose.symbol$col, "navyblue", "purple", "gold")
> trellis.par.get()$superpose.symbol$col[1:10] <- mycolors
Error in trellis.par.get()$superpose.symbol$col[1:10] <- mycolors : 
  invalid (NULL) left side of assignment

I don't understand what that error message is telling me.


回答1:


You should be using trellis.par.set() to set trellis graphical parameters. So:

trellis.par.set(superpose.symbol = list(col = mycolors))

Bear in mind that this will only change the settings for the currently active device, so that if you create a new graphical device, you will have to reset the color settings.

Also, this is explained in the help page ?trellis.par.get in the Details section. Please have a look there.



来源:https://stackoverflow.com/questions/12967798/how-to-change-lattice-graphics-default-groups-colors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!