【问题标题】:proportional line width ggplot2, in Gantt chart比例线宽 ggplot2,在甘特图中
【发布时间】:2017-06-08 18:24:52
【问题描述】:

我的目标是绘制与 data.frame 中的变量成比例的线宽,例如,在 here 中讨论过的主题。 我的应用程序(尽管问题可能与此无关)在甘特图中 adapted from here 中,如下所示:

library(reshape2)
library(ggplot2)

MA <- c("A", "B", "C")

dfr <- data.frame(
  name        = factor(MA, levels = MA),
  start.date  = as.Date(c("2012-09-01", "2013-01-01","2014-01-01")),
  end.date    = as.Date(c("2019-01-01", "2017-12-31","2019-06-30")),
  prozent     = c(1,0.5,0.75)*100
)
mdfr <- melt(dfr, measure.vars = c("start.date", "end.date"))

ggplot(mdfr, aes(value, name)) + geom_line(aes(size = prozent)) 

这会产生 我确实得到了不同的线宽,但是看起来与prozent 不成比例。

有没有办法使线宽prozent成比例

【问题讨论】:

  • 添加+ scale_size_area() 会产生你想要的吗?
  • 是的!谢谢,请将此作为答案发布。

标签: r ggplot2 gantt-chart


【解决方案1】:

只需添加+ scale_size_area():

ggplot(mdfr, aes(value, name)) +
    geom_line(aes(size = prozent)) +
    scale_size_area()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-30
    • 2014-09-20
    • 1970-01-01
    相关资源
    最近更新 更多