@Macux
        
        2015-12-01T06:51:57.000000Z
        字数 1896
        阅读 1076
    R语言_学习笔记
1、准备工作
> library(labeling)> library(ggplot2)
2、qplot()能做的事
> set.seed(1410)> dsmall <- diamonds[sample(nrow(diamonds),100),]> qplot(carat,price,data=dsmall)

> qplot(carat,price,colour=I("light blue"),data=dsmall)

> qplot(carat,price,data=diamonds,alpha=I(1/20),colour=I("blue"))

> qplot(carat,price,data=dsmall,geom=c("point","smooth"),span=0.2)

> qplot(carat,price,data=dsmall,geom=c("point","smooth"),span=1)

> qplot(carat,price,data=diamonds,geom=c("point","smooth"),method="gam",fomula=y~s(x,bs="cs"))

> qplot(color,price/carat,data=diamonds,geom="boxplot",fill=I("palegreen"))

> qplot(color,price/carat,data=diamonds,geom="jitter",alpha=I(1/40),colour=I("blue"))

> qplot(carat,data=diamonds,geom="density",colour=cut)

> qplot(carat,data=diamonds,geom="histogram",fill=cut,binwidth=0.1,xlim=c(0,3)) #设置xlim是画出原始图后,主动去调整的。默认是0~5。

> qplot(carat,data=diamonds,geom="histogram",fill=cut,binwidth=0.01,xlim=c(0,3))

> qplot(color,data=diamonds,geom="bar",fill=color)

> qplot(color,data=diamonds,geom="bar",weight=carat,fill=color)+scale_y_continuous("carat")
 
图形展示出,不同颜色的钻石之间的重量比较。
> qplot(date,unemploy / pop,data=economics,geom="line",color=I("orange"),size=I(0.7))

qplot(date,uempmed,data=economics,geom="line",color=I("darkslategray3"),size=I(0.7))

> year <- function(x) as.POSIXlt(x)$year +1900> qplot(unemploy / pop,uempmed,data=economics,geom="path",colour=year(date))

> qplot(carat,data=diamonds,facets=color~.,geom="histogram",binwidth=0.1,xlim=c(0,3),fill=color)

> qplot(carat,data=diamonds,facets=.~color,geom="histogram",binwidth=0.1,xlim=c(0,3),fill=color)

> qplot(carat,..density..,data=diamonds,facets=color~.,geom="histogram",binwidth=0.1,xlim=c(0,3),fill=color)
