Christoph Hanck
Christoph Hanck

Reputation: 353

proportional line width ggplot2, in Gantt chart

I aim to plot line widths proportional to a variable in a data.frame, a topic which has, for example, been discussed here. My application is (although the issue is probably not related to that) within a Gantt chart adapted from here as in:

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)) 

This yields enter image description here where I do get different line widths, which however do not look proportional to prozent.

Is there a way to make the line widths proportional to prozent?

Upvotes: 0

Views: 355

Answers (1)

Nate
Nate

Reputation: 10671

just add + scale_size_area():

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

enter image description here

Upvotes: 2

Related Questions