如何在ggplot2中添加纹理以填充颜色 [英] How to add texture to fill colors in ggplot2

查看:29
本文介绍了如何在ggplot2中添加纹理以填充颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 scale_brewer() 进行填充,这些颜色看起来很漂亮(在屏幕上和通过彩色打印机),但在使用黑白打印机时打印出的灰色相对均匀.我搜索了在线 ggplot2 文档,但没有看到任何关于添加纹理以填充颜色的信息.有没有官方的 ggplot2 方法来做到这一点,或者有没有人有他们使用的黑客?我所说的纹理是指对角线、反向对角线、圆点图案等,它们可以在黑白打印时区分填充颜色.

解决方案

ggplot 可以使用 colorbrewer 调色板.其中一些是复印"友好的.所以也许这样的事情对你有用?

ggplot(diamonds, aes(x=cut, y=price, group=cut))+geom_boxplot(aes(fill=cut))+scale_fill_brewer(palette="OrRd")

在这种情况下,OrRd 是在 colorbrewer 网页上找到的调色板:http://colorbrewer2.org/<块引用>

复印友好:这表明给定的配色方案将经得起黑白影印.不同的方案可以不能复印成功.亮度的差异应该是保留顺序方案.

I'm currently using scale_brewer() for fill and these look beautiful in color (on screen and via color printer) but print relatively uniformly as greys when using a black and white printer. I searched the online ggplot2 documentation but didn't see anything about adding textures to fill colors. Is there an official ggplot2 way to do this or does anyone have a hack that they use? By textures I mean things like diagonal bars, reverse diagonal bars, dot patterns, etc that would differentiate fill colors when printed in black and white.

解决方案

ggplot can use colorbrewer palettes. Some of these are "photocopy" friendly. So mabe something like this will work for you?

ggplot(diamonds, aes(x=cut, y=price, group=cut))+
geom_boxplot(aes(fill=cut))+scale_fill_brewer(palette="OrRd")

in this case OrRd is a palette found on the colorbrewer webpage: http://colorbrewer2.org/

Photocopy Friendly: This indicates that a given color scheme will withstand black and white photocopying. Diverging schemes can not be photocopied successfully. Differences in lightness should be preserved with sequential schemes.

这篇关于如何在ggplot2中添加纹理以填充颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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