R,ggplot2:geom_segment的宽度/大小

时间:2017-08-04 15:36:52

标签: r ggplot2

我想用不同宽度的段绘制时间轴,并随意调整段大小。

我正在使用ggplot和以下数据:

  instrument scope start_date   end_date
1          a     2 1977-01-01 1990-01-01
2          a     2 1990-01-01 1998-01-01
3          a     4 1998-01-01 2017-01-01
4          b     2 1994-01-01 1998-01-01
5          b     4 1998-01-01 2017-01-01

到目前为止,我一直在使用以下代码:

ggplot(df,aes(x=start_date, y=instrument)) +
  geom_segment(aes(x=start_date,xend=end_date,yend=instrument, size=scope))

geom_segment的宽度似乎得到了缩放"。换句话说,独立于我在4列中替换scope的值,我得到了视觉上相似的图:

Original plot

Plot with scope of 1000 instead of 4

我怎样才能避免段的大小自动缩放"并且任意增加/减少每个段的宽度?

要重现数据集:

df <- structure(list(instrument = c("a", "a", "a", "b", "b"), scope = c(2L, 
2L, 4L, 2L, 4L), start_date = structure(c(2557, 7305, 10227, 
8766, 10227), class = "Date"), end_date = structure(c(7305, 10227, 
17167, 10227, 17167), class = "Date")), row.names = c(NA, -5L
), class = "data.frame", .Names = c("instrument", "scope", "start_date", 
"end_date"))

0 个答案:

没有答案