R語言可視化(十二)

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

發佈了269 篇原創文章 · 獲贊 67 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章