#图层叠加的总体策略
library(ggplot2)
p<-data.frame(x=c(3,1,5),y=c(2,4,6),label=c("a","b","c"))
p
q<-ggplot(p,aes(x,y))+xlab(NULL)+ylab(NULL)
q+geom_point()+labs(title="geom_point")#加标题
q+geom_bar(stat="identity")+labs(title="geom_bar")
q+geom_line()+labs(title="线图")
q+geom_path()
q+geom_text(aes(label=label))
#展示数据分布
p<-ggplot(diamonds,aes(depth))+xlim(58,68)
p+geom_histogram(aes(y=..density..),binwidth=0.1)+facet_grid(cut~.)#分组对比
head(diamonds)
p+geom_histogram(aes(fill=cut),binwidth=0.1,position="fill")#条件密度图
p+geom_histogram(fill="blue",position="fill")
p+geom_freqpoly(aes(y=..density..,colour=cut),binwidth=0.1)#频率多边形图
q<-ggplot(diamonds,aes(cut,depth)
q+geom_boxplot()
ggplot(mpg,aes(class,cty,colour=class))+geom_jitter()#避免覆盖问题