如何更改莱迪思图形的默认组颜色? [英] How to change Lattice graphics default groups colors?

查看:102
本文介绍了如何更改莱迪思图形的默认组颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用groups时,莱迪思为每个组提供不同的颜色.示例:

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"))

但是,默认情况下,莱迪思只使用七种颜色,如上面的示例所示.如果您有七个以上的组,则Lattice会再次按顺序循环显示颜色,从而导致不同组中的数据具有相同的颜色.我从另一篇Stackoverflow文章中学到,这些颜色存储在trellis.par.get()$superpose.symbol$col中.我想使组颜色列表更长(而不必在打印调用中明确指定颜色).但是,我不知道如何更改此颜色列表. (这可能是由于对有关莱迪思语法或语义的一些基本事实不了解.)这说明了问题:

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.

推荐答案

您应该使用trellis.par.set()设置网格图形参数.所以:

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.

此外,详细信息部分的帮助页面?trellis.par.get中对此进行了说明.请在那里看看.

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

这篇关于如何更改莱迪思图形的默认组颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆