繁体   English   中英

如何使用ggplot2将几个系列绘制为线,将其中一个绘制为面积?

[英]How can I plot several series as lines and one of them as area using ggplot2?

我正在尝试完成以前在Excel中所做的事情,在相同的时间间隔内有多个时间序列,并希望将它们绘制为线(使用ggplot geom_line足够容易),但是其中之一应绘制为面积情节。

基本上是这样的:

期望

请注意,系列S_1被绘制为面积。

我已经尝试添加aes值等于区域序列值的geom_area():

ggplot(df.lines, aes(x=Index, y=Value, colour=Series)) + geom_line() + geom_area(aes(x=df.area$Index, y=df.area$S_1))

我怎样才能使用ggplot2完成这样的事情?

没有数据集很难测试(可以在示例中提供一个数据集,可以使用dput() ),但是在geom_area ,应该在data参数中进行选择。例如,像这样。

ggplot +
geom_area(data = df.area[df.area$Series == "S_1", ], aes(x=Index, y=Value)) 
  geom_line(data = df.lines, aes(x=Index, y=Value, colour=Series))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM