【问题标题】:ggplot2: changing colors of segments in geom_segment gantt chart?ggplot2:改变geom_segment甘特图中段的颜色?
【发布时间】:2014-10-15 04:33:02
【问题描述】:

我正在尝试在 ggplot2 中制作甘特图。我在更改 geom_segment() 中每个段的颜色和间距时遇到了麻烦

> head(g672)
mobility    start  endtime
1    active  0.00000  1.60157
3    active  1.60157 59.65837
5    active 59.65840 68.93415
7  immobile 68.93420 69.03430
9    active 69.03430 77.87629
11 immobile 77.87620 80.27855

我正在使用 geom_segment() 来生成图表:

ggplot(g672, aes(colour=mobility)) + 
  geom_segment(aes(x=start, xend=endtime, y=mobility, yend=mobility), size=15) +
  xlab("Duration") +
  theme_classic()

生成此图表:

我希望能够做 2 件事:1) 更改颜色和 2) 使 2 个条看起来彼此更接近,甚至让它们重叠(这些是相互排斥的类别,所以如果你是不做一个,你做另一个)。

欢呼并感谢您的任何建议

【问题讨论】:

    标签: r colors ggplot2 gantt-chart


    【解决方案1】:

    我的解决方案是使用一些字符作为yyend 值(这将使段重叠)。然后,您可以使用 theme()axis.text.y=axis.title.y= 从轴中删除此字符。您可以使用scale_color_manual() 更改颜色。

    ggplot(g672, aes(colour=mobility)) + 
          geom_segment(aes(x=start, xend=endtime, y="a", yend="a"), size=15) +
          xlab("Duration") +
          theme_classic()+
          scale_color_manual(values=c("black","green"))+
          theme(axis.text.y=element_blank(),
                axis.title.y=element_blank())
    

    【讨论】:

    • 是否有可能使它们彼此靠近以使这些片段彼此重叠?
    猜你喜欢
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-14
    • 2017-04-01
    • 1970-01-01
    • 2012-02-13
    • 1970-01-01
    相关资源
    最近更新 更多