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()的更多相关文章

  1. R语言、02 案例2-1 Pelican商店、《商务与经济统计》案例题

    编程教材 <R语言实战·第2版>Robert I. Kabacoff 课程教材<商务与经济统计·原书第13版> (安德森) P48.案例2-1 Pelican 商店 PS C: ...

  2. [原]CentOS7安装Rancher2.1并部署kubernetes (二)---部署kubernetes

    ##################    Rancher v2.1.7  +    Kubernetes 1.13.4  ################ ##################### ...

  3. 利用python进行数据分析2_数据采集与操作

    txt_filename = './files/python_baidu.txt' # 打开文件 file_obj = open(txt_filename, 'r', encoding='utf-8' ...

  4. Django项目:CRM(客户关系管理系统)--81--71PerfectCRM实现CRM项目首页

    {#portal.html#} {## ————————46PerfectCRM实现登陆后页面才能访问————————#} {#{% extends 'king_admin/table_index.h ...

  5. R基础学习(三)-- 简单练习(shiny+mysql+barplot)

    测试环境:win10+RStudio 提前准备: install.packages('shiny') install.packages('RMySQL') 数据表准备: 最终实现的界面效果如下:点击[ ...

  6. R语言barplot绘图函数

    barplot 函数用于绘制柱状图,下面对其常用的参数进行一个详细的解释: 1)height : 高度,通过这个参数可以指定要画多少个柱子以及每个柱子的高度,其值有两种格式, 第一种 :向量 vect ...

  7. R: 绘图 barplot

    问题:barplot 18.5.16 怎么绘制 barplot,用两种方式:基础绘图 & ggplot2解决方案: 基础绘图 barplot(height, width = 1, space ...

  8. R语言barplot ,掌握本篇的内容,基本的条形图都可以画了

    本篇主要想复现文章中的一张图,原图来源(Antibiotic resistome and its association with bacterial communities during sewag ...

  9. R语言barplot双坐标作图

    需要注意的是,设置其中的柱子的宽度,间隔的宽度.有公式如下 width为柱子的宽度 space为间隔宽度 barnumbers 为柱子数量 那么xlim的设置右侧范围为:(width + space) ...

  10. 简单介绍一下R中的几种统计分布及常用模型

    统计学上分布有很多,在R中基本都有描述.因能力有限,我们就挑选几个常用的.比较重要的简单介绍一下每种分布的定义,公式,以及在R中的展示. 统计分布每一种分布有四个函数:d――density(密度函数) ...

随机推荐

  1. 线程池(5)Executors.newScheduledThreadPool

    例子1(scheduleAtFixedRate):延迟2秒后,每隔3秒执行1次 ScheduledExecutorService es = Executors.newScheduledThreadPo ...

  2. 如何使用在Windows 下AspNetCore Api 和 consul

    在Windows 下如何使用 AspNetCore Api 和 consul https://blog.csdn.net/sD7O95O/article/details/80750803 一.概念:什 ...

  3. 我的grunt配置

    module.exports = function(grunt) { // 配置. grunt.initConfig({ pkg: grunt.file.readJSON('package.json' ...

  4. Tensorflow版Faster RCNN源码解析(TFFRCNN) (2)推断(测试)过程不使用RPN时代码运行流程

    本blog为github上CharlesShang/TFFRCNN版源码解析系列代码笔记第二篇   推断(测试)过程不使用RPN时代码运行流程 作者:Jiang Wu  原文见:https://hom ...

  5. JAVA基础之项目分包

    个人理解: 项目分层分包适合多人开发合作的,最好一个界面设置一个view,同时注释一定设置好,按照顺序:从前向后进行传递参数,从后向前进行传递返回值来进行判断是否真正的执行了sql语句(可以不返回), ...

  6. 转 winfrom如何通过http来进行通信,并且通过传递json格式的数据可接受json格式的数据

    string username = this.textBox1.Text; string password = this.textBox2.Text; string AA = HttpUtility. ...

  7. vue-cli版本更新(2.9.1)问题记录-2

    今天想把做好的页面放在手机端浏览,发现新版的vue-cli无论在PC还是手机都只能用localhost访问(127.0.0.1除外).....(这样还怎么让我用手机吃鸡了!TT),于是我在网上查找了一 ...

  8. UVALive 3942 Remember The Word (Tire)

    状态是DAG,因此方案用dp统计,dp[i] = sum(dp[i+len(x)]),x是以i开头的前缀且是单词,关键在于快速判断一个前缀是不是单词,可用Trie. 每一次转移的复杂度是O(maxle ...

  9. CentOS配置主机名和主机映射

    1.修改本机主机名 vi /etc/sysconfig/network 修改hostname HOSTNAME=s0 2.配置主机映射 vi /etc/hosts 修改内容如下 192.168.32. ...

  10. QT+event() + 事件过滤器

    其存在的意义: mywidget.h: #ifndef MYWIDGET_H #define MYWIDGET_H #include <QWidget> namespace Ui { cl ...