R语言支持很多图形,并且有些图形是非常少见的,可能也因为自己不是专业弄数据分析的所以就孤陋寡闻了,总结下目前学习到的图形。

条形图

这个图比较常见,很多数据统计软件都支持这种图形,这种图形可以很好的展示数据的汇总结果,可以简洁明了的方式表达数据背后的含义

> library(vcd)

> counts

> counts

None Some Marked

42 14 28

> barplot(counts,main="Simple Bar Plot",xlab="Improvement",ylab=""Frequency)

Error: unexpected symbol in "barplot(counts,main="Simple Bar Plot",xlab="Improvement",ylab=""Frequency"

> barplot(counts,main="Simple Bar Plot",xlab="Improvement",ylab="Freqency")

>

> barplot(counts,main="Horizontal Bar Plot",xlab="Frequency",ylab="Improvement",horiz=TRUE)

堆砌图

这个图是条形图的进化版本,它可以表达出更加丰富的含义,如果说条形图只能表达两个维度的结果,那么堆砌图则能表达三个维度的数据分析结果

library(vcd)

> counts

> counts

Placebo Treated

None 29 13

Some 7 7

Marked 7 21

> barplot(counts,main="Stacked Bar Plot",xlab="Treatment",ylab="Frequency",col=c("red","yellow","green"),legend=rownames(counts))

>

分组条形图

和上面的堆砌图一样的效果,只是数据的展现方式不一样。

> barplot(counts,main="Stacked Bar Plot",xlab="Treatment",ylab="Frequency",col=c("red","yellow","green"),legend=rownames(counts),beside=TRUE)

均值图

个人觉得和条形图类型,就图形而言,没有显著的差别。

states

means

> means

Group.1 x

1 Northeast 1.000000

2 South 1.737500

3 North Central 0.700000

4 West 1.023077

> means

> means

Group.1 x

3 North Central 0.700000

1 Northeast 1.000000

4 West 1.023077

2 South 1.737500

> barplot(means$x,names.arg = means$Group.1)

> title("Mean Illiteracy Rate")

>

>

> par(mar=c(5,8,4,2))

> par(las=2)

> counts

> barplot(counts,main="Treatment Outcome", horiz=TRUE, cex.name=0.8, names.arg = c("No Improvement","Some Improvement", "Marked Improvement"))

>

荆状图

和堆砌图类似,但是所有分组的高度都是一样的,唯一不同的则是分组中的色块面积大小,用来分析数据在某种情况下所占比例比较合适。

> library(vcd)

> counts

Error in table(Treatment, Improved) : object 'Treatment' not found

> attach(Arthritis)

> counts

> spine(counts,main="Spinogram Example")

> counts

Improved

Treatment None Some Marked

Placebo 29 7 7

Treated 13 7 21

饼图

最常见的图,不多说了

library(plotrix)

> par(mfrow=c(2,2))

> slices

> lbls

> pie(slices,labels=lbls,main="Simple Pie Chart")

>

> pct

> lbls2

> lbls2

[1] "US 20%" "UK 24%" "Australia 8%" "Germany 32%" "France 16%"

> pie(slices,labels=lbls,explode=0.1,main="3D Pie Chart ")

> pie(slices,labels=lbls2,col=rainbow(length(lbls2)),main="Pie Chart wit Precentage")

> pie3D(slices,labels=lbls,explode=0.1,main="3D Pie Chart ")

> mytable

> pie(mytable,labels=lbls3,main="Pie Chart from a Table\n (with sample sizes)")

扇形图

和饼图类型,不过这个图形还是比较少见的

> library(plotrix)

> slices

> lbls

> fan.plot(slices,labels=lbls,main="Fan Plot")

直方图

柱图,最常见的图,和之前提到的条形图类似。

> par(mfrow=c(2,2))

> hist(mtcars$mpg)

>

> hist(mtcars$mpg,breaks=12,col="red",xlab="Miles Per Gallon",main="Colored histogram with 12 bins")

>

>

> hist(mtcars$mpg,freq=FALSE,col="red",xlab="Miles Per Gallon",main="Histogram, rug plot, density curve")

> rug(jitter(mycars$mpg)) #轴须图

> lines(density(mtcars$mpg),col="blue",lwd=2) #密度曲线

> x

> h

> xfit

> yfit

> yfit

> lines(xfit,yfit,col="blue",lwd=2)

> box()

> mtcars$mpg

[1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4 10.4

[17] 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7 15.0 21.4

核密度图

这个图形比较少见,有点像原始版本的热点图,用来显示变量的密度关系。

> library(sm)

>par(mfrow=c(2,1))

> d

> plot(d)

> d

> plot(d,main="Kernel Density of Miles Per Gallon")

> polygon(d,col="red",border="blue")

> attach(mtcars)

> cyl.f

> sm.density.compare(mpg,cyl,xlab="Miles Per Gallon")

> title(main="MPG Distribution by Car Cylinders")

>

> colfill

> legend(locator(1),levels(cyl.f),fill=colfill)

箱线图

这个图也比较有意思,它主要关注一组观察变量的5个指标:Min,1/4,mean,4/3,Max。第一次发现这么有意思的分析方式,不过在日常的统计中,这5ge指标应该是经常被使用的,所以箱线图也是非常实用的一种图形。

boxplot(mtcars$mpg,main="Box plot",ylab="Miles per Gallon")

>

> boxplot(mpg~cyl,data=mtcars,main="Car Mileage Data", xlab="Number of Cylinders",ylab="Miles Per Gallon")

boxplot(mpg~cyl,data=mtcars,notch=TRUE,varwidth=TRUE,col="red",main="Car Mileage Data",xlab="Number of Cylinders",ylab="Miles Per Gallon") #有对称效果的箱线图,该图形包含了变量密度信息

#分组箱线图

mtcars$cyl.f

> mtcars$cyl.f

mtcars$am.f

> mtcars$am.f

[1] standard standard standard auto auto auto auto auto auto

[10] auto auto auto auto auto auto auto auto standard

[19] standard standard auto auto auto auto auto standard standard

[28] standard standard standard standard standard

Levels: auto standard

> boxplot(mpg~am.f*cyl.f,data=mtcars,varwidth=TRUE,col=c("gold","darkgreen"),main="MPG Distribution by Auto Type",xlab="Auto Type",ylab="Miles Per Gallon")

>

小提琴图

和箱线图的分析套路类似,但是提供更加明确的变量密度分布信息。

> library(vioplot)

x1

> x2

> x3

> vioplot(x1,x2,x3,names=c("4 cyl","6 cyl","8 cyl"),col="gold")

> title("Violin Plots of Miles Per Gallon",ylab="Miles Per Gallon",xlab="Number of Cylinders")

点图

也是一种比较常见的图,它的进化版本应该是散点图

> dotchart(mtcars$mpg, labels=row.names(mtcars),cex=.7,main="Gas Mileage for Car Models",xlab="Miles Per Gallon")

>

#分组散点图

> x

> x$cyl

> x$color[x$cyl==4]

> x$color[x$cyl==6]

> x$color[x$cyl==8]

> dotchart(x$mpg,labels=row.names(x),cex=.7,groups=x$cyl,gcolor="black",color=x$color,pch=19,main="Gas Mileage for Car Models\ngrouped by cylinder", xlab="Miles Per Gallon")

R语言acres92 region_R语言学习笔记(四)相关推荐

  1. R语言acres92 region_R语言作Circos图之进阶篇:圈圈套圈圈的法门

    如果把一组数据表组成一个列表(list),panel.fun则迭代用于各个数据表.再随机生成一个list来观察它的结构: bedlist = list( bed01=generateRandomBed ...

  2. R语言与抽样技术学习笔记(Jackknife)

    R语言与抽样技术学习笔记(Randomize,Jackknife,bootstrap) Jackknife算法 Jackknife的想法在我很早的一篇博客<R语言与点估计学习笔记(刀切法与最小二 ...

  3. R语言与函数估计学习笔记(函数模型的参数估计)

    R语言与函数估计学习笔记 毫无疑问,函数估计是一个比参数估计要复杂得多的问题,当然也是一个有趣的多的问题.这个问题在模型未知的实验设计的建模中十分的常见,也是我正在学习的内容的一部分. 关于函数估计我 ...

  4. c语言/c++转Java学习笔记---基础问题

    c语言/c++转Java学习笔记---基础问题 1.java注释 2.数组的定义和使用 定义 使用 3.类 4.this 的使用 5.继承 6.super的使用 7.包 8.修饰符 成员的访问控制符( ...

  5. c语言编程实例解析精粹,C语言实例解析精粹学习笔记——35(报数游戏)

    实例35: 设由n个人站成一圈,分别被编号1,2,3,4,--,n.第一个人从1开始报数,每报数位m的人被从圈中推测,其后的人再次从1开始报数,重复上述过程,直至所有人都从圈中退出. 实例解析: 用链 ...

  6. JavaScript学习笔记(四)(DOM)

    JavaScript学习笔记(四) DOM 一.DOM概述 二.元素对象 2.1 获取方式 (1).通过ID获取一个元素对象,如果没有返回null (2).通过`标签名`获取一组元素对象,,如果没有返 ...

  7. 华清远见fs4412开发板学习笔记(四)

    fs4412开发板学习笔记(四) 今天的课程安排 1.复习 1.1 VIM 编辑器 [1] vim + filename 打开 [2] 工作模式 命令模式 编辑模式 底行模式 [3] 模式切换 命令- ...

  8. MySQL高级学习笔记(四)

    文章目录 MySQL高级学习笔记(四) 1. MySql中常用工具 1.1 mysql 1.1.1 连接选项 1.1.2 执行选项 1.2 mysqladmin 1.3 mysqlbinlog 1.4 ...

  9. esp8266舵机驱动_arduino开发ESP8266学习笔记四—–舵机

    arduino开发ESP8266学习笔记四-–舵机 使用时发现会有ESP8266掉电的情况,应该是板上的稳压芯片的限流导致的,观测波形,发现当舵机运转时,电源线3.3V不再是稳定的3.3V,大概是在3 ...

最新文章

  1. 2018CTDC风暴来袭乌镇 互联网大佬再续前缘
  2. 纯 CSS 实现波浪效果!
  3. JS技巧:兼容性导出表格为Excel文件
  4. 推荐系统笔记:基于SVD的协同过滤
  5. 【Cocosd2d实例教程二】地图编辑器Tiled的安装使用
  6. Docker 升级 npm v3 报错 cross-device link not permitted, rename
  7. 行向量,列向量,行主序矩阵,列主序矩阵
  8. 何谓 SQL 注入,这个漫画告诉你
  9. Lesson Plan 教学计划 翻译
  10. java process 中断_从Java运行外部程序,读取输出,允许中断
  11. 那天有个小孩跟我说LINQ(三)
  12. Unable to process Jar entry
  13. java中printreader类_java字符流,字符文件输入流FileReader类介绍
  14. python全栈马哥_马哥2018python全栈视频
  15. stm32f103r6最小系统原理图_stm32f103c8t6封装及最小系统原理图
  16. 优思学院|“元宇宙“是什么东西?
  17. 组织敏捷程序:第2部分,用于管理敏捷程序的网络
  18. 给ESXI添加自定义网卡驱动
  19. 知瓜数据爬取-机构排行榜
  20. 基于cc2530获取ds18b20温度值

热门文章

  1. android notifydatasetchanged 刷新错误,Android 调用notifyDataSetChanged方法失败解决办法
  2. 没有背水一战,腾讯忽然又有梦想了?!
  3. 上周技术关注:流氓软件及反流氓软件的技术分析
  4. 未来30年前沿科技风口
  5. php流量计算单位,数据业务流量的计量单位及换算
  6. 【vue案例】vue实现tab选项卡
  7. Paper Writting2 - 写作框架
  8. VMWare 虚拟机如何扩展磁盘空间并挂载到已存在的根目录
  9. GAN对抗生成网络学习笔记(三)DCGAN原理
  10. 惊心动魄-微信抢红包传播活动