ggplot 1

#ggplot学习
##qplot相关知识
set.seed(1410)
dsmall=diamonds[sample(nrow(diamonds),100),]
qplot(carat,price,data=diamonds)
qplot(log(carat),log(price),data=diamonds)
qplot(carat,x*y*z,data=diamonds)
##颜色大小形状和其他图形属性
qplot(carat,price,data=dsmall,colour=color)
qplot(carat,price,data=dsmall,shape=cut)
##透明度
qplot(carat,price,data=dsmall,alpha=I(1/100))
qplot(carat,price,data=dsmall,alpha=I(1/1000))
#geom
#向图中添加平滑曲线
qplot(carat,price,data=dsmall,geom=c("point","smooth"))
qplot(carat,price,data=diamonds,geom=c("point","smooth"))
##利用method参数来选择许多不同的平滑器
#曲线的平滑程度是由span参数控制的,取值范围为0(很不平滑)到1(很平滑)
qplot(carat,price,data=dsmall,geom=c("point","smooth"),span=0.2)
qplot(carat,price,data=dsmall,geom=c("point","smooth"),span=1)
##当数据超过一千时用method,调用mgcv包来实现
qplot(carat,price,data=dsmall,geom=c("point","smooth"),
      method="gam",formula=y~s(x))
qplot(carat,price,data=dsmall,geom=c("point","smooth"),
      method="gam",formule=y~s(x,bs="cs"))
#method="lm"拟合的是线性模型,你也可以通过formule=y~poly(x,2)来拟合一个二次多项式、
#加载splines包可以使用自然样条
qplot(carat,price,data=dsmall,geom=c("point","smooth"),
      method="lm")
qplot(carat,price,data=dsmall,geom=c("point","smooth"),
      method="lm",formula=y~ns(x,5))
#method="rlm"与lm类似,在mass包里面,但采用了一种更稳健的拟合算法,使得结果对异常值不太敏感
##箱型图和扰动图
#扰动点图中的图形重叠问题可以通过半透明颜色解决,alpha参数
qplot(color,price/carat,data=diamonds,geom="jitter",alpha=I(1/5))
qplot(color,price/carat,data=diamonds,geom="jitter",alpha=I(1/50))
qplot(color,price/carat,data=diamonds,geom="jitter",alpha=I(1/100))
##直方图和密度曲线图
qplot(carat,data=diamonds,geom="histogram")
qplot(carat,data=diamonds,geom="density")
##尝试多种组距
qplot(carat,data=diamonds,geom="histogram",binwidth=1,xlim=c(0,3))
qplot(carat,data=diamonds,geom="histogram",binwidth=0.1,xlim=c(0,3))
qplot(carat,data=diamonds,geom="histogram",binwidth=0.01,xlim=c(0,3))
##图形映射
qplot(carat,data=diamonds,geom="density",colour=color)
qplot(carat,data=diamonds,geom="histogram",fill=color)
##条形图
qplot(color,data=diamonds,geom="bar")
qplot(color,data=diamonds,geom="bar",weight=carat)+scale_y_continuous("carat")
##时间序列中的线条图和路径图
#失业率和失业星期数的中位数
qplot(date,unemploy/pop,data=economics,geom="line")
qplot(date,uempmed,data=economics,geom="line")
##其他
qplot(carat,price,data=dsmall,xlab="Price($)",ylab="Weight(carats)",
main="Price-weight relationship"      )
qplot(carat,price/carat,data=dsmall,ylab=expression(frac(price,carat)),
      xlab="Weight(carats)",
      main="Small diamonds",xlim=c(.2,1))
qplot(carat,price,data=dsmall,log="xy")
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值