ggplot2 "grammar of graphics"繪圖的文法
資料源:data frame
----------------------------------
ggplot 繪圖文法的組成部分
A data frame
aesthetic mappings:如何将資料與顔色、大小和點對應
geoms; 頁面上的特定對象點線形
facets: 多面闆條件繪圖
stats: 統計變換
scales: 不同變量如何編碼
coordinate: 坐标系
summary:觀察ggplot
----------------------------------
g<-ggplot(data,aes(x=,y=))
color ##顔色(使用factor值)
alpha ##透明度
+geom_point() ##繪圖
color
size
alpha
aes()
color #分組分色顯示
+geom_smooth(method="lm") ##加入回歸曲線(預設平滑曲線)
size
linetype ##線條格式
method
se ##是否顯示置信區間
col
+facet_grid(.~x) ##格網分面繪圖(在繪圖前訂立因子)
(y~x)
margions ##是否顯示total情況
+facet_wrap(y~x) ##纏繞分面,按從左到右從上到下的“纏繞”順序進行排列
nrow
ncol
+theme() ##全局變量
+labs() ##label
x
y
title
+theme_gray() ##預設的灰背景
+theme_bw() ##黑白背景
base_family ##字型
base_size
+ylim(-3,3) ##篩選y值在-3-3範圍内的資料
+coord_cartesian(ylim=c(-3,3)) ##顯示-3到3部分的圖像(保證資料完整性)
+ggtitle() ##标題
等分連續變量為因子變量
---cutpoints<-quantile(maacs$logno2,seq(0,1,length=4),na.rm=true)
---maacs$no2dec<-cut(macs$logno2,cutpounts)