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. LNMP下使用Phabricator(一)

    首先是安装. 安装过程并不复杂,英文看得懂的可以自己看原文 https://secure.phabricator.com/book/phabricator/article/installation_g ...

  2. namedJDBC查询

    import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import org.spring ...

  3. Spring boot中应用jpa jpa用法

    https://blog.csdn.net/u012582402/article/details/78717705

  4. mysql 无法启动 unkown command

    1. https://serverfault.com/questions/490656/mysql-not-starting-error-usr-sbin-mysqld-unknown-option- ...

  5. python 8 函数

    调用函数 Python内置了很多有用的函数,我们可以直接调用. 要调用一个函数,需要知道函数的名称和参数,比如求绝对值的函数abs,只有一个参数.可以直接从Python的官方网站查看文档: 也可以在交 ...

  6. linux下火狐浏览器安装flash player插件

    1 去官方网站下载flash player 安装包.后缀名为.tar.gz,假设名称为flash.tar.gz 默认在桌面 2 下载后解压缩,使用以下命令 #tar -zxvf /root/Deskt ...

  7. js得到当前页面的url信息

    所有的代码都是可用,而且附了图片的,不过是直接用我自己的文章地址,所以有些显示的有点奇怪. 大家可以找个网址试试代码是否可行. 1,设置或获取对象指定的文件名或路径. console.log(wind ...

  8. 函数补充:动态参数,函数嵌套,global与nonlocal关键

    一丶动态参数 1.*args 位置参数,动态传参 def func(*food): print(food) print(func("米饭","馒头"," ...

  9. javaweb-servlet生成简单的验证码

    package com.serv; import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedIma ...

  10. u-boot剖析(一)----Makefile分析

    由于u-boot比较庞大,所以我们分开来分析,对于一个大型的项目我们想快速的了解其代码架构和内容,最方便的方法就是分析Makefile,所以我们今天以三星的s3c2440来分析Makefile.我们今 ...