R ggplot2:包括多个趋势线

时间:2017-10-10 15:23:24

标签: r ggplot2

我正在尝试绘制三个时间序列线图,并为每个线图包含一个线性趋势线。我正在使用ggplot2。这就是我所拥有的:

p<- ggplot(bds, aes(year2)) + 
geom_line(aes(y = estabs_entry_rate, colour = "Entry Rate")) + 
geom_smooth(method="lm") + 
geom_line(aes(y = estabs_exit_rate, colour = "Exit Rate")) +
geom_smooth(method="lm") +
geom_line(aes(y=job_creation_rate-job_destruction_rate+5, colour="Net Jobs")) +
geom_smooth(method="lm")
p

我尝试在每次geom_smooth(method="lm")电话后加入geom_line()。但是,我收到以下错误消息:

错误:stat_smooth需要以下缺少美学:y

我想要的是estabs_entry_rateestabs_exit_ratejob_creation_rate-job_destruction_rate对时间的情节,全部在一个地块上,每个地图都有线性趋势线。

我怎么能在ggplot2中做到这一点?

非常感谢。

编辑:以下是bds数据的示例:

year2   estabs_entry_rate   estabs_exit_rate   job_creat_rate   job_destr_rate
1982    15.4                11.5                18.3            17.0
1983    12.6                11.4                18.2            18.6
1984    14.3                10.9                16.5            13.6
1985    14.0                10.5                19.8            15.6

0 个答案:

没有答案