【发布时间】:2021-11-08 06:00:05
【问题描述】:
我有多个相同格式的数据框,我想使用 ggplot 在同一个图表中创建多条曲线。每个数据框都有一年的数据,从 1956 年到 2019 年。例如:
Year1956 <- data.frame(prob=c(5, 10, 20, 30, 100), Qmcs=c(1000, 500, 50, 10, 5))
Year1957 <- data.frame(prob=c(1, 3, 25, 35, 100), Qmcs=c(800, 600, 100, 50, 30))
可以在同一个图表中手动绘制这些多个对象,其中 ... 是 Year1958 到 Year2018
ggplot()+
geom_line(data=Year1956, aes(x=prob, y=Qmcs))+
geom_line(data=Year1957, aes(x=prob, y=Qmcs))+
...
geom_line(data=Year2019, aes(x=prob, y=Qmcs))
由于有很多数据帧,有没有办法在循环中执行此操作?提前谢谢你。
【问题讨论】: