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)