GGPLOT2灰度打印(ggplot2 for grayscale printouts)

2019-07-04 01:04发布

GGPLOT2产生用于屏幕/彩色打印花式图,但灰色背景和颜色干扰打印它们为灰度时。 为了更好readablility,我宁愿禁用灰色背景和使用产生两种不同的灰色或不同种类的填充招区分群体的深浅颜色的发电机。

Answer 1:

**编辑**更新代码: geom_bar需要stat

theme_bw可能是你追求的。 如果你正在策划具有填充如酒吧GEOM,该scale_fill_grey功能将让您对灰色色调控制。 如果你正在策划,有一个颜色的GEOM(如线或点),该scale_colour_grey功能会给你的控制。 据我所知,ggplot不绘制图案填充。 假设你正在密谋吧,下面就绘制在灰色背景的彩色条。

library(ggplot2)

data <- read.table(text = 
"type Year  Value 
 A    2000  3
 B    2000  10
 C    2000  11
 A    2001  4
 B    2001  5
 C    2001  12", sep = "", header = TRUE)

(p = ggplot(data = data, aes(x = factor(Year), y = Value)) +       
  geom_bar(aes(fill = type), stat="identity", position = "dodge"))

以下更改彩色酒吧的灰色阴影。 需要注意的是酒吧的一个背景丢失。

(p = p + scale_fill_grey(start = 0, end = .9))

下面除去灰色背景。

(p = p + theme_bw())

一个点有一个变色,不填充。 因此,使用灰色色调上的点,你需要这样的事情。

(p = ggplot(data = data, aes(x = factor(Year), y = Value)) +       
  geom_point(aes(colour = type), size = 5) +
  scale_colour_grey(start = 0, end = .9) +
  theme_bw())



Answer 2:

其他人应答者都集中在自动调整线/条的颜色。 在印刷出版物,但是,我不希望有浅灰色线等,因为它们是难以识别和区分。 下面是自动调整线类型(我不知道是可能的,直到前一天)的解决方案。

library(ggplot2)
theme_set(theme_bw())

data <- read.table(text = 
"type Year  Value 
 A    1998  6
 A    1999  8
 A    2000  6
 A    2001  7
 B    1998  4
 B    1999  5
 B    2000  10
 B    2001  5
 C    1998  8
 C    1999  6
 C    2000  9
 C    2001  8", sep = "", header = TRUE)

p <- ggplot(data=data,
            aes(x = factor(Year),
                y = Value,
                linetype = factor(type)))
p <- p + geom_line(aes(group = factor(type)),
                   size=0.8)

请注意,您可以轻松地定制ggplot主题 。 下面是使用另一种结果我自己的简约ggplot主题 :

(抗锯齿看起来当导出为PDF比它这里[巴布亚新几内亚]的方式更好。)



Answer 3:

这里是你想要的一个简单的例子

library(ggplot2)

data <- read.table(text = 
  "Letter      Year    Value 
 A           1998    5
                B           1999    10
                C           2000    15
                A           2000    7
                B           2001    15
                C           2002    20", sep = "", header = TRUE)
ggplot(data = data, aes(x = factor(Year), y = Value, colour = Letter)) +       
  geom_line(aes(group = Letter)) + scale_colour_grey() +
  theme(panel.background = element_rect(fill='white', colour='black'))



文章来源: ggplot2 for grayscale printouts
标签: r ggplot2