R:如何改变格子(levelplot)颜色主题?

时间:2022-10-30 22:59:33

The default theme on my installation is something which maps the values to pink and cyan. How to change it for example to a gray scale theme?

我安装的默认主题是将值映射为粉色和青色。如何将其更改为灰度主题?

5 个解决方案

#1


15  

You can use

您可以使用

library(lattice)
lattice.options(default.theme = standard.theme(color = FALSE))

which turns on black-and-white suitable for printing. I've also played with things like

打开适合打印的黑白。我也玩过类似的东西

sb <- trellis.par.get("strip.background") 
sb[["col"]][1] <- "lightgray"
trellis.par.set("strip.background", sb) 

which changes just the header background.

这只会改变标题背景。

And I thought people only asked ggplot2 questions here :) Nice to see some lattice for a change.

而且我认为人们只在这里问ggplot2问题:)很高兴看到一些格子换一个。

#2


9  

Thanks for the answers guys! It also helped me to find more information on the subject. I learned that I can control the scales of gray using for example the following:

谢谢你们的答案!它还帮助我找到有关该主题的更多信息。我了解到我可以控制灰度等级,例如:

levelplot(my_var, col.regions = gray(0:100/100))

which gives me 100 shades of gray from black (0) to white (1).

这给了我100个灰色阴影,从黑色(0)到白色(1)。

I'm using the function to plot gray scale images (photos) which I've pre-processed to a double matrix. I don't know if it's the best possible approach, but so far it works and I believe it gives me more options for graphing than the basic displaying options in the EBImage and rimage libraries. I don't know how I'd alter the palette to match displaying color images, but I'm glad I didn't have to do that so far...

我正在使用该功能绘制我已经预处理成双矩阵的灰度图像(照片)。我不知道它是否是最好的方法,但到目前为止它的工作原理并且我相信它给我提供了更多的图形选项,而不是EBImage和rimage库中的基本显示选项。我不知道如何改变调色板以匹配显示彩色图像,但我很高兴到目前为止我没有必要这样做...

#3


5  

There are many ways to accomplish your request. The simplest is:

有很多方法可以完成您的请求。最简单的是:

trellis.device(color = FALSE)

another is

另一个是

ltheme <- canonical.theme(color = FALSE) ## in-built B&W theme 
ltheme$strip.background$col <- "transparent" ## change strip bg 
lattice.options(default.theme = ltheme) ## set as default 

See this mail archive item: Re: [R] specify lattice black-and-white theme for more info.

请参阅此邮件存档项目:Re:[R]指定格子黑白主题以获取更多信息。

#4


2  

You may also want to consider using panel.levelplot.raster, as it reduces the figure size sizably, as I recently found out. Combining this tip with changing trellis settings in general, here are a following examples:

您可能还想考虑使用panel.levelplot.raster,因为它可以减少数字大小,正如我最近发现的那样。通常将此提示与更改格子设置相结合,以下是以下示例:

trellis.par.set(regions=list(col=topo.colors(100)))
levelplot(volcano, panel = panel.levelplot.raster)

levelplot(volcano, panel = panel.levelplot.raster,
          par.settings=list(regions=list(col=topo.colors(100))))

The second method is deceptive because the trellis settings are in fact being changed globally. I didn't know about the col.regions argument though - that's pretty nice as it seems to change the color theme locally.

第二种方法具有欺骗性,因为网格设置实际上是全局更改的。我不知道col.regions论证 - 这很好看,因为它似乎在本地改变了颜色主题。

#5


2  

The only one that worked for me is:

唯一适合我的是:

>trellis.par.set(canonical.theme(color = FALSE)) 

#1


15  

You can use

您可以使用

library(lattice)
lattice.options(default.theme = standard.theme(color = FALSE))

which turns on black-and-white suitable for printing. I've also played with things like

打开适合打印的黑白。我也玩过类似的东西

sb <- trellis.par.get("strip.background") 
sb[["col"]][1] <- "lightgray"
trellis.par.set("strip.background", sb) 

which changes just the header background.

这只会改变标题背景。

And I thought people only asked ggplot2 questions here :) Nice to see some lattice for a change.

而且我认为人们只在这里问ggplot2问题:)很高兴看到一些格子换一个。

#2


9  

Thanks for the answers guys! It also helped me to find more information on the subject. I learned that I can control the scales of gray using for example the following:

谢谢你们的答案!它还帮助我找到有关该主题的更多信息。我了解到我可以控制灰度等级,例如:

levelplot(my_var, col.regions = gray(0:100/100))

which gives me 100 shades of gray from black (0) to white (1).

这给了我100个灰色阴影,从黑色(0)到白色(1)。

I'm using the function to plot gray scale images (photos) which I've pre-processed to a double matrix. I don't know if it's the best possible approach, but so far it works and I believe it gives me more options for graphing than the basic displaying options in the EBImage and rimage libraries. I don't know how I'd alter the palette to match displaying color images, but I'm glad I didn't have to do that so far...

我正在使用该功能绘制我已经预处理成双矩阵的灰度图像(照片)。我不知道它是否是最好的方法,但到目前为止它的工作原理并且我相信它给我提供了更多的图形选项,而不是EBImage和rimage库中的基本显示选项。我不知道如何改变调色板以匹配显示彩色图像,但我很高兴到目前为止我没有必要这样做...

#3


5  

There are many ways to accomplish your request. The simplest is:

有很多方法可以完成您的请求。最简单的是:

trellis.device(color = FALSE)

another is

另一个是

ltheme <- canonical.theme(color = FALSE) ## in-built B&W theme 
ltheme$strip.background$col <- "transparent" ## change strip bg 
lattice.options(default.theme = ltheme) ## set as default 

See this mail archive item: Re: [R] specify lattice black-and-white theme for more info.

请参阅此邮件存档项目:Re:[R]指定格子黑白主题以获取更多信息。

#4


2  

You may also want to consider using panel.levelplot.raster, as it reduces the figure size sizably, as I recently found out. Combining this tip with changing trellis settings in general, here are a following examples:

您可能还想考虑使用panel.levelplot.raster,因为它可以减少数字大小,正如我最近发现的那样。通常将此提示与更改格子设置相结合,以下是以下示例:

trellis.par.set(regions=list(col=topo.colors(100)))
levelplot(volcano, panel = panel.levelplot.raster)

levelplot(volcano, panel = panel.levelplot.raster,
          par.settings=list(regions=list(col=topo.colors(100))))

The second method is deceptive because the trellis settings are in fact being changed globally. I didn't know about the col.regions argument though - that's pretty nice as it seems to change the color theme locally.

第二种方法具有欺骗性,因为网格设置实际上是全局更改的。我不知道col.regions论证 - 这很好看,因为它似乎在本地改变了颜色主题。

#5


2  

The only one that worked for me is:

唯一适合我的是:

>trellis.par.set(canonical.theme(color = FALSE))