加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

R语言中ggplot2中的geom参数的选项以及实例图形

(2014-07-03 20:39:45)
标签:

r数据可视化

分类: R语言
> require(ggplot2)
Loading required package: ggplot2

Attaching package: ‘ggplot2’

The following object is masked _by_ ‘.GlobalEnv’:

    diamonds

> attach(diamonds)
The following objects are masked _by_ .GlobalEnv:

    x, y
> #geom几种不同参数的不同图形样式效果以及示例图形
> #如果数据是单维的连续性数据,则geom的默认值就是"histogram"
> #如下例:
> qplot(carat,colour="red")
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
http://s14/mw690/0027nJCegy6KabY3mX36d&690

 

> #如果qplot命令中包含x,y数据,且都是连续型数据,则geom的默认值即使"points",即绘制散点图,如下例:
> qplot(carat,price)
http://s13/mw690/0027nJCegy6Kac0pFa44c&690


 
> #geom=“smooth”则会在图形中绘制一条拟合平滑曲线,并将曲线和标准误差表现出来,如下图:
> qplot(carat,price,geom="smooth")
geom_smooth: method="auto" and size of largest group is >=1000, so using gam with formula: y ~ s(x, bs = "cs"). Use 'method = x' to change the smoothing method.
http://s2/mw690/0027nJCegy6Kac6wmoFb1&690


> #如果需要同时体现散点图以及拟合曲线,则可以用以下方法:
> qplot(carat,price,geom=c("point","smooth"))
geom_smooth: method="auto" and size of largest group is >=1000, so using gam with formula: y ~ s(x, bs = "cs"). Use 'method = x' to change the smoothing method.
> #以上的警告信息是涉及平滑拟合方法的差异,数据量小于1000的默认方法是loess,即局部回归方法,span参数规定平滑程度,0表示很不平滑,1表示非常平滑
> #对于样本量大于1000的,需要添加以下参数:method="gam",formula=y~s(x,bs="cs")
> #如下例:
> qplot(carat,price,geom=c("point","smooth"),method="gam",formula=y~s(x,bs="cs"))
> #geom="boxplot"则是用来绘制箱线图,见下例:
> qplot(cut,carat,geom="boxplot")
> #geom="density"可以用来绘制概率密度图,见下例:
> qplot(carat,geom="density")
> #geom="jitter"可以用来绘制干扰点图,用于分组区分,见下例
> qplot(cut,carat,geom="jitter",colour=I("red"))
> #geom="bar"用来绘制柱状图,见下例:
> qplot(cut,geom="bar",fill=I("green"))
> #geom="line"用来绘制折线图,多用于时间序列分析,见下例:
> qplot(date,unemploy/pop,geom="line",data=economics)

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有