【发布时间】:2016-12-20 14:27:34
【问题描述】:
我想绘制单个散点图,显示两个站月降雨的不同颜色。例如 A 站 1 月降雨量值红色、2 月降雨量黄色和 B 站 1 月降雨量值蓝色、2 月绿色等出现在图例上。此外,我想为也出现在图例上的两个站点数据添加一条平滑线,例如 A 站的红色平滑线和 B 站的蓝色平滑线。 在此链接中,您可以找到两个站的 CSV 数据: https://drive.google.com/file/d/0B3fQ9_46L-O0TjJwYmF6UThNSGs/view?usp=sharing https://drive.google.com/file/d/0B3fQ9_46L-O0ZXVYb3lzZDBZaHM/view?usp=sharing
以下是我尝试过但未能成功的代码。
#reading csv file of ramoili station of rautahat[Scatterplot of two stations][1]
ram = read.csv('preci_ramoili.csv',header=TRUE, stringsAsFactors=FALSE)
#reading CSV file of gaur station of rautahat
gaur= read.csv('preci_Gaur.csv',header=TRUE, stringsAsFactors=FALSE)
#gaur rainfall
rain <- data.frame(index(agg),stack(as.data.frame(coredata(agg))))
rain
head(rain)
tail(rain)
names(rain)[1] <- "Year"
names(rain)[2] <- "Rainfall"
names(rain)[3] <- "Month"
#ramoili rainfall
rain1<-data.frame(index(core),stack(as.data.frame(coredata(core))))
rain1
head(rain1)
names(rain1)[1] <- "Year"
names(rain1)[2] <- "Rainfall"
names(rain1)[3] <- "Month"
head(rain1)
#ramoili premonsoon rainfall
rain1_pre<-data.frame(index(core[,3:5]),stack(as.data.frame(coredata(core[,3:5]))))
head(rain_pre)
tail(rain1_pre)
names(rain1_pre)[1] <- "Year"
names(rain1_pre)[2] <- "Rainfall"
names(rain1_pre)[3] <- "Month"
#ggplot of two stations gaur and ramoili yearly rainfall of rautahat in same plot
p9 <- ggplot(rain, aes(x =Year, y=Rainfall, size=Rainfall)) + geom_point(shape = 21,color = "#000000", fill = "#40b8d0") +
geom_smooth(aes(fill="Gaur"), colour="darkblue", size=1)
p10 <- p9 + geom_point(data=rain1, aes(x =Year, y=Rainfall, color=Month )) +
geom_smooth(data=rain1, aes(fill="Ramoili"), colour="red", size=1)+
ggtitle(" Yearly rainfall at two stations of Rautahat")+
scale_fill_manual(name="Stations", values=c("blue", "red"))
print(p10)
【问题讨论】:
-
数据有帮助,但您的问题和代码缺少对
agg和core的引用。它还有助于列出您在示例代码中使用的包。
标签: r ggplot2 time-series timeserieschart