样本量多的话应该是这样的图,但本例中用的样本量少,但步骤一样。
所用数据如下:
代码:
mydata<-read.table("ljs.csv",header=TRUE,sep=",")
mydata %>% filter(nkill > 0) -> mydatap #筛选出死亡人数大于0的;
mydatap %>% group_by(iyear,region) %>% summarise(nkills = sum(nkill)) %>% ungroup() ->mydatas
colnames(mydatas)<-c("Year","Region","Killed")
library(ggplot2)
ggplot(data =mydatas, aes(x = Year, y = Killed, colour = Region)) +geom_line() + geom_point() + theme_bw()
输出结果:
相当于是画了4条时间序列
|
请发表评论