R-barplot()
barplot这个函数啊。。。坑。。。度娘的很多解决方案都不对,只好重新看回manual再做测试==
本文参考的是:
https://stat.ethz.ch/R-manual/R-devel/library/graphics/html/par.html
https://stat.ethz.ch/R-manual/R-devel/library/graphics/html/barplot.html
# for colorspace
library(RColorBrewer)
# read data
data <- as.matrix(read.table("./species.txt",header=T,check.names=F))
colors = c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#FFFF33", "#A65628","#F781BF", "#999999", "#1B9E77", "#D95F02","#7570B3", "#E7298A", "#66A61E", "#E6AB02", "#A6761D", "#666666", "#66C2A5", "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3", "#1A1A1A", "#67001F")
labs=colnames(data)
# new a pdf
pdf("./species_taxonomy_barplot.pdf",width=40,height=20)
# 边空的大小由mai参数或mar参数控制,它们都是四个元素的向量,分别规定下方、左方、上方、右方的边空大小,其中mai取值的单位是英寸,而mar的取值单位是文本行高度。
par(mai=c(0.7,1,0.3,20))
# beside=F means stacked bars
# border=NA means omit borders of bars
# xasx=i means x-axis style: internal
# Style "r" (regular) first extends the data range by 4 percent at each end and then finds an axis with pretty labels that fits within the extended range.
# Style "i" (internal) just finds an axis with pretty labels that fits within the original data range.
# mgp: margin line
# las=2 means perpendicular to axis
# cex.names : expansion factor for axis names (bar labels).
# axes=F no axes drawn
# cex.lab=1.2 放大率
# xaxt : Specifying "n" suppresses plotting of the axis. The standard value is "s"
rownames(data)=data[,1]
bp = barplot(data, legend.text=F,beside=F, xlab="", col=colors, border=NA, xaxs="r", mgp=c(3,0.2,0.5), las=2, axes=F, ylab="Relative abundance (%)",cex.lab=1,xaxt="s")
# tcl=-0.2 means The length of tick marks as a fraction of the height of a line of text.
axis(2, las=2, cex.axis=1, mgp=c(3,0.4,0.5), tcl=-0.2)
# usr : A vector of the form c(x1, x2, y1, y2) giving the extremes of the user coordinates of the plotting region.
#cex_x = ((par("usr")[2]-par("usr")[1])/29)*0.6
# xpd=TRUE means all plotting is clipped to the figure region.
# cex是放大倍数
# adj=1 means right-justified text
# srt: string rotation degree
#text(bp, par("usr")[3]-0.4,labels = colnames(data),xpd=TRUE,cex=1,adj=1,srt=45,font=0.1)
legend(par("usr")[2],par("usr")[4]+1,cex=0.9,bty="n",x.intersp=0.4,pt.cex=1,rownames(data),fill=colors,text.font=1,ncol=4,xpd=TRUE)
abline(h=axTicks(2),lty=2,col=rgb(0,0,0,0.2))
dev.off()
R-barplot()的更多相关文章
- R语言、02 案例2-1 Pelican商店、《商务与经济统计》案例题
编程教材 <R语言实战·第2版>Robert I. Kabacoff 课程教材<商务与经济统计·原书第13版> (安德森) P48.案例2-1 Pelican 商店 PS C: ...
- [原]CentOS7安装Rancher2.1并部署kubernetes (二)---部署kubernetes
################## Rancher v2.1.7 + Kubernetes 1.13.4 ################ ##################### ...
- 利用python进行数据分析2_数据采集与操作
txt_filename = './files/python_baidu.txt' # 打开文件 file_obj = open(txt_filename, 'r', encoding='utf-8' ...
- Django项目:CRM(客户关系管理系统)--81--71PerfectCRM实现CRM项目首页
{#portal.html#} {## ————————46PerfectCRM实现登陆后页面才能访问————————#} {#{% extends 'king_admin/table_index.h ...
- R基础学习(三)-- 简单练习(shiny+mysql+barplot)
测试环境:win10+RStudio 提前准备: install.packages('shiny') install.packages('RMySQL') 数据表准备: 最终实现的界面效果如下:点击[ ...
- R语言barplot绘图函数
barplot 函数用于绘制柱状图,下面对其常用的参数进行一个详细的解释: 1)height : 高度,通过这个参数可以指定要画多少个柱子以及每个柱子的高度,其值有两种格式, 第一种 :向量 vect ...
- R: 绘图 barplot
问题:barplot 18.5.16 怎么绘制 barplot,用两种方式:基础绘图 & ggplot2解决方案: 基础绘图 barplot(height, width = 1, space ...
- R语言barplot ,掌握本篇的内容,基本的条形图都可以画了
本篇主要想复现文章中的一张图,原图来源(Antibiotic resistome and its association with bacterial communities during sewag ...
- R语言barplot双坐标作图
需要注意的是,设置其中的柱子的宽度,间隔的宽度.有公式如下 width为柱子的宽度 space为间隔宽度 barnumbers 为柱子数量 那么xlim的设置右侧范围为:(width + space) ...
- 简单介绍一下R中的几种统计分布及常用模型
统计学上分布有很多,在R中基本都有描述.因能力有限,我们就挑选几个常用的.比较重要的简单介绍一下每种分布的定义,公式,以及在R中的展示. 统计分布每一种分布有四个函数:d――density(密度函数) ...
随机推荐
- 基于 opencv图像去噪
-------------------开通头条号-------------------- 实验名称 图像去噪 实验目的 1.掌握算术均值滤波器.几何均值滤波器.谐 ...
- 拖拽调整Div大小
今天写了一天这个jquery插件: 可以实现对div进行拖拽来调整大小的功能. (function ($) { $.fn.dragDivResize = function () { var delta ...
- Flask 学习系列(三)---Jinjia2使用过滤器
再Jinjia2中过滤器是一种转变变量输出内容的技术.··过滤器通过管道符号“|与变量链接,并且可以通过圆括号传递参数” .举例说明: {{my_variable|default('my_variab ...
- webpack.config.js====webpack-dev-server开发服务器配置
1. 安装webpack-dev-server(在指定目录下),一定要先安装完毕webpack webpack-cli之后在安装webpack-dev-server 一个基于expressjs的开发服 ...
- @PropertySource
功能 加载指定的属性文件(*.properties)到 Spring 的 Environment 中.可以配合 @Value 和 @ConfigurationProperties 使用. @Prope ...
- struts2 ognl表达式访问值栈
1:简单的说,值栈是对应每一个请求对象的轻量级的数据存储中心,在这里统一管理着数据,供Action.Result.Interceptor等Struts2的其他部分使用,这样数据被集中管理起来而不凌乱. ...
- 【迷你微信】基于MINA、Hibernate、Spring、Protobuf的即时聊天系统:4.技术简介之Spring
欢迎阅读我的开源项目<迷你微信>服务器与<迷你微信>客户端 Spring是一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One ...
- C语言的sprintf()和snprintf()
1.sprintf()函数 送格式化输出到字符串中,返回实际输出到字符串中的个数. 例如: char buffer[80]; sprint(buffer,"1234567890") ...
- C#之winform实现文件拖拽功能【转】
将一个文件拖拽到窗体的某个控件时,将该控件的路径显示在该控件上,只要拿到了路径自然可以读取文件中的内容了 将一个控件的属性AllowDrop设置为true,然后添加DragDrop.DragEnter ...
- python之道11
day11作业 请写出下列代码的执行结果: 例一: def func1(): print(**'in func1'**) def func2(): print(**'in func2'**) ret ...