如何区分geom_bar中没有颜色的条形:ggplot

时间:2016-01-29 12:02:17

标签: r ggplot2 bar-chart

注意:类似的问题出现在link,但我提出了一个单独的问题,原因是:1)只有一个hack被提供给previos问题我认为会使代码不必要复杂2)我想2013年之后,可能会为此

建议修复

我使用以下代码绘制条形图/堆栈

  ggplot(finaldataframe,aes(day,score))+
    geom_bar(aes(fill=identify),stat="identity",position = "dodge",width = .7, show.legend = TRUE)+
    labs(x= "Day of the Month", y="Anomaly Score") +
    scale_fill_discrete(name="Method", labels=c("Mean","Maximum","Cumulative \n sum"))+
  theme(axis.text= element_text(color="Black"))+ scale_x_continuous(breaks=seq(1,31,5))

输出的一部分为

enter image description here

这个图的问题是,一旦我通过黑白打印机打印它很难区分不同的堆栈。有没有办法让堆栈在黑白打印上可以区分。我正在寻找一些像这样的东西:

enter image description here

对于复制,这是数据帧的输入:

> dput(finaldataframe)
finaldataframe = structure(list(day = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 
24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 
29L, 30L, 31L), score = c(0, 0.02, 0.01, 0, 0.02, 0.01, 0.01, 
0.02, 0.02, 0.28, 0.24, 0.01, 0.94, 0.22, 0.25, 0.01, 0.31, 0.22, 
0.24, 0.83, 0.4, 0.44, 0.06, 0.02, 0.37, 0.07, 0.12, 0.06, 0.1, 
0.06, 0.1, 0, 0.05, 0.04, 0.02, 0.05, 0.01, 0.02, 0.03, 0.04, 
0.37, 0.36, 0.04, 1, 0.28, 0.34, 0.03, 0.55, 0.35, 0.32, 1, 0.71, 
1, 0.13, 0.04, 0.47, 0.12, 0.17, 0.1, 0.18, 0.1, 0.14, 0, 0.02, 
0.01, 0, 0.02, 0.01, 0.01, 0.02, 0.02, 0.3, 0.25, 0.01, 1, 0.23, 
0.27, 0, 0.33, 0.24, 0.26, 0.89, 0.42, 0.47, 0.06, 0.02, 0.4, 
0.07, 0.13, 0.06, 0.11, 0.06, 0.1), identify = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("Mean", 
"Maximum", "Cummulative Sum"), class = "factor")), .Names = c("day", 
"score", "identify"), row.names = c(NA, 93L), class = "data.frame")

0 个答案:

没有答案