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. Mysql和oracle字段类型与java对象类型对应表收藏

    https://blog.csdn.net/michaelzhou224/article/details/16827029 Mysql Oracle Java BIGINT NUMBER(19,0) ...

  2. Hypertext Application Language(HAL)

    Hypertext Application Language(HAL) HAL,全称为Hypertext Application Language,它是一种简单的数据格式,它能以一种简单.统一的形式, ...

  3. 中间件注册可以除了可以使用Startup之外,还可以选择StartupFilter

    中间件注册可以除了可以使用Startup之外,还可以选择StartupFilter 中间件的注册除了可以借助Startup对象(DelegateStartup或者ConventionBasedStar ...

  4. 《深入理解java虚拟机》笔记(8)类的加载机制

    一.类加载机制 类加载器将类的.class文件中的二进制数据读入到内存中,将其放在方法区内,然后在堆区创建一个java.lang.Class对象,用来封装类在方法区内的数据结构.类的加载的最终产品是位 ...

  5. 讲明白combineByKey()算子,不是谈源码

    简单介绍 combineByKey()是最通用的对key-value型rdd进行聚集操作的聚集函数(aggregation function).类似于aggregate(),combineByKey( ...

  6. 仙人掌(cactus)

    题目描述LYK 在冲刺清华集训(THUSC)!于是它开始研究仙人掌,它想来和你一起分享它最近研究的结果.如果在一个无向连通图中任意一条边至多属于一个简单环(简单环的定义为每个点至多经过一次),且不存 ...

  7. JavaScript中的小陷阱(不定期更新。。)

    1. var scores = [1, 2, 3]; var total = 0; for (var score in scores) { total += score; } var mean = t ...

  8. SQL2000,2005,2008安装在一台机子上

    工欲善其事,必先利其器.本机的系统是在网上自己下载的,是32位windows7旗舰版.因为学习,需要在一台机子上同时安装SQL Server2000,2005,2008三个版本的数据库.先是在网上查了 ...

  9. 不小心踩到的XMAPP的N种问题

    1.在win10上的xampp集成环境中安装mongo扩展 按照网上搜索的下载对应文件后,在phpinfo里面还是找不到mongo的扩展信息,后面也是请教同事帮忙解决: http://www.theg ...

  10. [20190620]日常学习记录(三)-初识promise及vuex

    在学习promise之前重温了Ajax的原生js实现, 在原生js中发送一个http请求首先new XMLHttpRequest() 然后定义状态变更事件 浏览器监听请求的状态,触发不同状态下相应的代 ...