r语言课程_10高阶绘图_第1页
r语言课程_10高阶绘图_第2页
r语言课程_10高阶绘图_第3页
r语言课程_10高阶绘图_第4页
r语言课程_10高阶绘图_第5页
已阅读5页,还剩33页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、10. R高阶绘图内容概要直方图柱状图饼形图散点图箱线图地图金字塔图直方图hist(x, breaks =Sturges, # breaks语句设定分组数量 freq = NULL, # 默认为频度输出,freq=FALSE 为按密度输出density = NULL, #默认没有填充,density=20(数字可改),有填充angle = 45, # 接density语句,填充线的倾斜度,默认=45col = NULL, # col设定颜色,默认黑色border = NULL, # border设定不同颜色main = paste(Histogram of , xname), # main可以

2、自己设定题目ylim = NULL, #ylim一般默认,可改变xlab = xname, # xlab设定自己的labylab, #设定自己的ylabelaxes = TRUE,# 绘图默认含坐标轴) hist(x)hist(x, col = red) hist(leaflife, longev, col = red, xlab = Leaf longevity (yr), main = Leaf longevity histgram) hist(leaflife, longev, col = red, xlab = Leaf longevity (yr), main = Leaf long

3、evity histgram, yaxt = n, border = red)axis(2, las = 2)hist(log10(leaflife, longev),col = red, xlab = Leaf longevity (yr),main = Leaf longevity histgram, axes = F, border = red)axis(2, las = 2)axis(1, at = log10(c(0.5, 1, 2, 4), label = c(0.5, 1, 2, 4)柱状图library(sciplot)bargraph.CI(x.factor, respons

4、e,group=NULL, col=NULL, density=NULL, angle=NULL, lc=TRUE, uc=TRUE, legend=FALSE, ncol=1, ylim=NULL, xpd=FALSE, data, .) # 加载sciplot包# x轴上的分类变量# 响应变量# 分组变量,默认为空# 颜色,可以按分组指定颜色数量# 柱子中加入其他线条的密度# 柱子中加入其他线条是的角度# 误差下限 改成FALSE为不显示误差下限# 误差上限,功能同上# 显示图例,默认不显示图例# 图例显示的列数# 设定ylim# 默认文本均在绘图框里,设定TRUE可超越# data指定要

5、绘图的数据对象bargraph.CI(x.factor = rain, response = longev, group = soilp, data = leaflife, legend = T, ylab = Leaf longevity, xlab = Precipitation) bargraph.CI(x.factor = rain, response = longev, group = soilp, data = leaflife, legend = TRUE, ylab = Leaf longevity, xlab = Precipitation, ncol = 1, col =

6、black, angle = c(45, 135), density = 20) 堆栈图barplot(height, width = 1, space = NULL, horiz = FALSE, density = NULL, angle = 45, col = NULL, xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, axes = TRUE, .) #矩阵数据#柱子宽度设置#柱子之间距离#图形垂直输出# 填充线条密度# 填充线条角度# 颜色# x标示# y标示# x轴刻度范围# y轴刻度范围# 默认显示坐标轴、刻度barplot(

7、dat, ylab = Fraction of explained variance,) barplot(dat, ylab = Fraction of explained variance, border = white, legend = TRUE) barplot(dat, ylab = Fraction of explained variance, border = white, legend = TRUE, xlim = c(0, 8) barplot(dat, xlab = Fraction of explained variance, border = white, horiz

8、= TRUE) f = barplot(dat, xlab = Fraction of explained variance, border = white, horiz = TRUE) 饼形图pie(x, # x为一维数组数据col = NULL, # 颜色border = NULL, ) # 扇形边界颜色设定, 为FALSE效果好pie(large.abund, col = rainbow(length(large.abund) pie2(sort(large.abund), col = rainbow(length(large.abund), border = FALSE, cex =

9、0.8)3D饼图library(plotrix)# 加载plotrix包pie3D(x,#同饼形图theta=pi/6,# 视角col=NULL,# 颜色设定labels=NULL,# 标记说明labelpos=NULL,# 标记位置explode=0,# 扇形裂开性shade=0.8,# 阴影.) pie3D(pieval, explode = 0.2, labels = pielabels) 散点图library(openair)scatterPlot(mydata, x = nox, y = no2, z = NA, method = scatter, type = default, s

10、mooth = FALSE, linear = FALSE, mod.line = FALSE, cols = hue, log.x = FALSE, log.y = FALSE, .) # 加载openair包#数据框# 指示x变量#指示y变量# 默认z缺失# 方法散点图# 类型默认缺失,可以指定一个分类变量# 局部平滑# 线性回归# 拟合线# 散点颜色scatterPlot(mydata = leaflife, x = longev, y = lma, type = rain) scatterPlot(mydata = leaflife, x = longev, y = lma, type

11、 = rain, smooth = TRUE) scatterPlot(mydata = leaflife, x = longev, y = lma, type = rain, linear = TRUE) 箱线图boxplot(x,x是一个公式col = NULL, 设定颜色log = , 对数转换horizontal = FALSE, 箱线图默认为垂直显示) boxplot(longev site, data = leaflife, xlab = site, ylab = Leaf longevity (yr) 箱线图(ggplot2模式)library(ggplot2)#加载ggplot

12、2包ggplot (data=NULL,#一个数据框格式的数据aes(x,# x轴上的分类变量y,# y轴上的分类变量fill)# fill 如果不是x轴上分类变量,双因素交叉)+geom_boxplot()# 作箱线图ggplot(leaflife, aes(x = rain, y = longev, fill = rain) + geom_boxplot()ggplot(leaflife, aes(x = rain, y = longev, fill = soilp) + geom_boxplot()地图-中国地图地图-世界地图3D图library(fields)drape.plot(x,

13、 y, z,horizontal = TRUE, theta = 30, phi = 20,.) # 加载fields包# x轴上数值向量, 为一递增数列# y轴数值向量,同上# z是矩阵,行的长度同x轴向量长度,列长度为y轴向量长度# 图例默认水平显示(位于图的下侧)# 延x-y轴水平方向视角# 延z轴水平方向视角drape.plot(x, y, volcano, col = terrain.colors(128), theta = 30, phi = 30)3D绘图动画金字塔图Try it!利用sciplot包中的bargraph.CI函数针对leaflife数据做site为分组变量的单因

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论