ggplot2折線圖
> library(ggplot2)
>
> N<-20 df1 <- data.frame(x=sort(rnorm(N)),y=sort(rnorm(N))) df2 <-
> data.frame(x=df1$x+0.1*rnorm(N),y=df1$y+0.1*rnorm(N))
所有圖層共享數據源和美學映射參數
> ggplot(df1,aes(x,y,colour=x+y))+ geom_line(size=1)+
> geom_point(shape=16,size=5)+
> guides(color=guide_colorbar(title="Point\nLine"))
#所有圖層僅共享數據源
ggplot(df1,aes(x,y))+
geom_line(aes(colour=x+y),size=1)+
geom_point(aes(fill=x+y),color="black",shape=21,
size=5)+
scale_fill_distiller(name="Point",palette="YlOrRd")+
scale_color_distiller(name="Line",palette="Blues")
#各圖層對象均使用獨立的數據源與美學映射參數
ggplot()+
geom_line(aes(x,y,colour=x+y),df1,size=1)+
geom_point(aes(x,y,fill=x+y),df2,color="black",
shape=21, size=5)+
scale_fill_distiller(name="Point",palette="YlOrRd")+
scale_color_distiller(name="Line",palette="Blues")
參考資料1:https://github.com/EasyChart/Beautiful-Visualization-with-R/
參考資料2:https://blog.csdn.net/tandelin/article/details/87719623