ggplot2用于灰度打印输出 [英] ggplot2 for grayscale printouts
问题描述
**编辑**更新的代码: geom_bar
需要一个 stat
。
theme_bw
可能就是您要做的。如果你正在绘制一个填充像条的geom,那么 scale_fill_grey
函数可以让你控制灰色阴影。如果您正在绘制具有颜色的几何图形(如线条或点), scale_colour_grey
函数将为您提供控件。据我所知,ggplot不会绘制图案填充。假设你正在绘制条形图,以下将在灰色背景上绘制彩色条。
library(ggplot2)
data< - read.table(text =
)类型年值
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(color = type),size = 5)+
scale_colour_grey(start = 0,end = .9)+
theme_bw())
ggplot2 produces fancy graphs for screen/color prints, but the gray background and the colors interfere when printing them to grayscale. For better readablility, I'd prefer to disable the gray background and use color generators that produce either different shades of gray or different kinds of filling strokes to distinguish the groups.
** EDIT ** Updated code: geom_bar
requires a stat
.
theme_bw
could be what you're after. If you are plotting a geom that has a fill such as bars, the scale_fill_grey
function will give you control over the shades of grey. If you are plotting a geom that has a colour (such as a line or points), the scale_colour_grey
function will give you the control. As far as I know, ggplot does not plot patterned fills. Assuming you're plotting bars, the following will plot coloured bars on a grey background.
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"))
The following changes the coloured bars to shades of grey. Note that one of the bars gets lost in the background.
(p = p + scale_fill_grey(start = 0, end = .9))
The following removes the grey background.
(p = p + theme_bw())
A point has a colour, not a fill. So to use shades of grey on points, you would need something like this.
(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())
这篇关于ggplot2用于灰度打印输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!