1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > R plot图片背景设置为透明_万能转换:R图和统计表转成发表级的Word PPT Excel HTM

R plot图片背景设置为透明_万能转换:R图和统计表转成发表级的Word PPT Excel HTM

时间:2022-06-15 19:42:50

相关推荐

R plot图片背景设置为透明_万能转换:R图和统计表转成发表级的Word PPT Excel HTM

R包export可以轻松的将R绘制的图和统计表输出到 Microsoft Office (Word、PowerPoint和Excel)、HTML和Latex中,其质量可以直接用于发表。

你和PPT高手之间,就只差一个iSlide

Excel改变了你的基因名,30% 相关Nature文章受影响,NCBI也受波及

特点

可以用命令将交互式R图或ggplot2Latticebase R图保存到Microsoft Word、Powerpoint或其他各种位图或矢量格式。

完全可编辑的Powerpoint矢量格式输出,支持手动整理绘图布局。

统计分析的输出保存为Excel、Word、PowerPoint、Latex或HTML文档的表格形式。

自定义R输出格式。

安装

export包可以在Windows、Ubuntu和Mac上跨平台运行。不过有些Mac发行版默认情况下没有安装cairo设备,需要自行安装。如果Mac用户已安装XQuartz,这个问题就解决了,它可以从/免费获得。

官方CRAN发布

install.packages("export")

该包主要包括以下几种转换

graph2bitmap

graph2office

graph2vector

rgl2bitmap 转换3D图

table2office

table2spreadsheet

table2tex

graph2bitmap: 将当前R图保存到bmp文件中

graph2png: 将当前R图保存到png文件中

graph2tif: 将当前R图保存到TIF文件中

graph2jpg: 将当前R图保存为JPEG文件

使用帮助信息如下:

graph2bitmap(x = NULL, file = "Rplot", fun = NULL, type = c("PNG","JPG", "TIF"),

aspectr = NULL, width = NULL, height = NULL, dpi = 300,scaling = 100,

font =ifelse(Sys.info()["sysname"] == "Windows", "Arial",

"Helvetica")[[1]], bg = "white", cairo = TRUE,

tiffcompression = c("lzw", "rle", "jpeg", "zip", "lzw+p", "zip+p"),

jpegquality = 99, ...)

aspectr: 期望纵横比。如果设置为空,则使用图形设备的纵横比。

width: 所需宽度(英寸);可以与期望的纵横比aspectr组合。

height: 所需高度(英寸);可以与期望的纵横比aspectr组合。

scaling: 按一定比例缩放宽度和高度。

font: PNG和TIFF输出中标签所需的字体; Windows系统默认为Arial,其他系统默认为Helvetica。

bg: 所需的背景颜色,例如“白色”或“透明”。

cairo: 逻辑,指定是否使用Cairographics导出。

tiffcompression: 用于TIF文件的压缩。

jpegquality: JPEG压缩的质量。

准备开始

安装完export包后,先调用该包

library(export)

ggplot2绘图

library(ggplot2)

library(datasets)

x=qplot(Sepal.Length, Petal.Length, data = iris,

color = Species, size = Petal.Width, alpha = I(0.7))

qplot()的意思是快速作图,利用它可以很方便的创建各种复杂的图形,其他系统需要好几行代码才能解决的问题,用qplot只需要一行就能完成。

使用半透明的颜色可以有效减少图形元素重叠的现象,要创建半透明的颜色,可以使用alpha图形属性,其值从0(完全透明)到1(完全不透明)。更多ggplot2绘图见ggplot2高效实用指南 (可视化脚本、工具、套路、配色)(往期教程更有很多生物信息相关的例子)。

鸢尾花(iris)是数据挖掘常用到的一个数据集,包含150个鸢尾花的信息,每50个取自三个鸢尾花种之一(setosa,versicolourvirginica)。每个花的特征用下面的5种属性描述萼片长度(Sepal.Length)、萼片宽度(Sepal.Width)、花瓣长度(Petal.Length)、花瓣宽度(Petal.Width)、类(Species)。

在console里展示数据图 (长宽比自己调节):

导出图形对象

# 需运行上面的ggplot2绘图

# Create a file name

# 程序会自动加后缀

filen # filen

# There are 3 ways to use graph2bitmap():

### 1. Pass the plot as an object

graph2png(x=x, file=filen, dpi=400, height = 5, aspectr=4)

graph2tif(x=x, file=filen, dpi=400, height = 5, aspectr=4)

graph2jpg(x=x, file=filen, dpi=400, height = 5, aspectr=4)

导出当前绘图窗口展示的图

### 2. Get the plot from current screen device

# 注意这个x,是运行命令,展示图像

x

graph2png(file=filen, dpi=400, height = 5, aspectr=4)

graph2tif(file=filen, dpi=400, height = 5, aspectr=4)

graph2jpg(file=filen, dpi=400, height = 5, aspectr=4)

导出自定义函数输出的一组图

### 3. Pass the plot as a functio

plot.fun print(qplot(Sepal.Length, Petal.Length, data = iris,

color = Species, size = Petal.Width, alpha = 0.7))

}

graph2png(file=filen, fun=plot.fun, dpi=400, height = 5, aspectr=4)

graph2tif(file=filen, fun=plot.fun, dpi=400, height = 5, aspectr=4)

graph2jpg(file=filen, fun=plot.fun, dpi=400, height = 5, aspectr=4)

转换后的图形:

与Office系列的交互

大部分图的细节修改都是用代码完成的,不需要后续的修饰;但如果某一些修改比较特异,不具有程序的通用性特征,或实现起来比较困难,就可以考虑后期修改。比如用AI文章用图的修改和排版。熟悉PPT的,也可以用PPT,这时R的图导出PPT,就要用到graph2office系列函数了。

graph2ppt: 将当前R图保存到Microsoft Office PowerPoint/LibreOffice Impress演示文稿中。

graph2doc:将当前的R图保存到Microsoft Office Word/LibreOffice Writer文档中。

函数参数展示和解释

graph2office(x = NULL, file = "Rplot", fun = NULL, type = c("PPT", "DOC"),

append = FALSE, aspectr = NULL, width = NULL, height = NULL,scaling = 100,

paper = "auto", orient = ifelse(type[1] == "PPT","landscape", "auto"),

margins = c(top = 0.5, right = 0.5, bottom = 0.5, left= 0.5),

center = TRUE, offx = 1, offy = 1, upscale = FALSE, vector.graphic = TRUE, ...)

margins: 预设留白边距向量。

paper: 纸张尺寸——“A5”至“A1”用于Powerpoint导出,或“A5”至“A3”用于Word输出;默认“auto”自动选择适合您的图形的纸张大小。如果图太大,无法在给定的纸张大小上显示,则按比例缩小。

orient: 所需的纸张方向-“自动”,“纵向”或“横向”; Word输出默认为“自动”,Powerpoint默认为“横向”。

vector.graphic: 指定是否以可编辑的向量DrawingML格式输出。默认值为TRUE,在这种情况下,编辑Powerpoint或Word中的图形时,可以先对图形元素进行分组。如果设置为FALSE,则将该图以300 dpi的分辨率栅格化为PNG位图格式。(栅(shān)格化,是PS中的一个专业术语,栅格即像素,栅格化即将矢量图形转化为位图。)

同样有3种导出方式

# 需运行上面的ggplot2绘图

# Create a file name

filen # filen

# There are 3 ways to use graph2office():

### 1. Pass the plot as an object

# 导出图形对象

graph2ppt(x=x, file=filen)

graph2doc(x=x, file=filen, aspectr=0.5)

### 2. Get the plot from current screen device

# 导出当前预览窗口呈现的图

x

graph2ppt(file=filen, width=9, aspectr=2, append = TRUE)

graph2doc(file=filen, aspectr=1.7, append =TRUE)

### 3. Pass the plot as a function

# 导出自定义函数输出的一系列图

graph2ppt(fun=plot.fun, file=filen, aspectr=0.5, append = TRUE)

graph2doc(fun=plot.fun, file=filen, aspectr=0.5, append = TRUE)

导出到office(ppt和word)中的图形,是可编辑的:

其它导出到ppt的例子(设置长宽比)

graph2ppt(file="ggplot2_plot.pptx", aspectr=1.7)

增加第二张同样的图,9英寸宽和A4长宽比的幻灯片 (append=T,追加)

graph2ppt(file="ggplot2_plot.pptx", width=9, aspectr=sqrt(2), append=TRUE)

添加相同图形的第三张幻灯片,宽度和高度固定

graph2ppt(file="ggplot2_plot.pptx", width=6, height=5, append=TRUE)

禁用矢量化图像导出

graph2ppt(x=x, file=filen, vector.graphic=FALSE, width=9, aspectr=sqrt(2), append = TRUE)

用图填满幻灯片

graph2ppt(x=x, file=filen, margins=0, upscale=TRUE, append=TRUE)

输出矢量图

graph2svg: 将当前的R图保存为SVG格式

graph2pdf: 将当前的R图保存为PDF格式

graph2eps: 将当前的R图保存为EPS格式

函数参数解释

graph2vector(x = NULL, file = "Rplot", fun = NULL, type = "SVG",aspectr = NULL,

width = NULL, height = NULL, scaling = 100,

font = ifelse(Sys.info()["sysname"] == "Windows",

"Arial","Helvetica")[[1]], bg = "white", colormodel = "rgb",

cairo = TRUE,fallback_resolution = 600, ...)

fallback_resolution: dpi中的分辨率用于栅格化不支持的矢量图形。

#需运行上面的ggplot2绘图

# Create a file name

filen # filen # There are 3 ways to use graph2vector():

### 1. Pass the plot as an object

# 导出图形对象

graph2svg(x=x, file=filen, aspectr=2, font = "Times New Roman",

height = 5, bg = "white")

graph2pdf(x=x, file=filen, aspectr=2, font = "Arial",

height = 5, bg = "transparent")

graph2eps(x=x, file=filen, aspectr=2, font = "Arial",

height = 5, bg = "transparent")

# 导出当前预览窗口呈现的图

### 2. Get the plot from current screen device

x

graph2svg(file=filen, aspectr=2, font = "Arial",

height = 5, bg = "transparent")

graph2pdf(file=filen, aspectr=2, font = "Times New Roman",

height = 5, bg = "white")

graph2eps(file=filen, aspectr=2, font = "Times New Roman",

height = 5, bg = "white")

# 导出自定义函数输出的一系列图

### 3. Pass the plot as a function

graph2svg(file=filen, fun = plot.fun, aspectr=2, font = "Arial",

height = 5, bg = "transparent")

graph2pdf(file=filen, fun=plot.fun, aspectr=2, font = "Arial",

height = 5, bg = "transparent")

graph2eps(file=filen, fun=plot.fun, aspectr=2, font = "Arial",

height = 5, bg = "transparent")

转换3D图形

rgl2png: 将当前的rgl 3D图形保存为PNG格式。

rgl2bitmap(file = "Rplot", type = c("PNG"))

# Create a file name

filen # filen

# Generate a 3D plot using 'rgl'

x = y = seq(-10, 10, length = 20)

z = outer(x, y, function(x, y) x^2 + y^2)

rgl::persp3d(x, y, z, col = 'lightblue')

# Save the plot as a png

rgl2png(file = filen)

# Note that omitting 'file' will save in current directory

生成的3D图形:

将生成的3D图形保存为PNG格式:

输出统计结果到表格table2spreadsheet

table2excel: 导出统计输出到Microsoft Office Excel/ LibreOffice Calc电子表格中的一个表.

table2csv:将统计输出以CSV格式导出到表中(“,”表示值分隔,“。”表示小数)

table2csv2: 将统计输出以CSV格式导出到表中(“;”表示值分隔,”,”表示小数)

table2spreadsheet(x = NULL, file = "Rtable", type = c("XLS", "CSV",

"CSV2"), append = FALSE, sheetName = "new sheet", digits = 2,

digitspvals = 2, trim.pval = TRUE, add.rownames = FALSE, ...)

sheetName: 一个字符串,给出创建的新工作表的名称(仅针对type==”XLS”)。它必须是惟一的(不区分大小写),不受文件中任何现有工作表名称的影响。

digits:除具有p值的列外,要显示所有列的有效位数的数目。

digitspvals:具有p值的列要显示的有效位数的数目。

# Create a file name

filen # filen

# Generate ANOVA output

fit=aov(yield ~ block + N * P + K, data = npk) # 'npk' dataset from base 'datasets'

x=summary(fit)

# Save ANOVA table as a CSV

### Option 1: pass output as object

# 输出对象

table2csv(x=x,file=filen, digits = 1, digitspvals = 3, add.rownames=TRUE)

# 屏幕输出导出到文件

### Option 2: get output from console

summary(fit)

table2csv(file=filen, digits = 2, digitspvals = 4, add.rownames=TRUE)

# Save ANOVA table as an Excel

# Without formatting of the worksheet

x

table2excel(file=filen, sheetName="aov_noformatting", digits = 1, digitspvals = 3, add.rownames=TRUE)

# 更多参数

# With formatting of the worksheet

table2excel(x=x,file=filen, sheetName="aov_formated", append = TRUE, add.rownames=TRUE, fontName="Arial", fontSize = 14, fontColour = rgb(0.15,0.3,0.75), border=c("top", "bottom"), fgFill = rgb(0.9,0.9,0.9), halign = "center", valign = "center", textDecoration="italic")

原始数据的表格:

转换格式之后的,在console中的数据:

文件(csv和excel)中表格数据:

导出为Word中的表,再也不用复制粘贴调格式了table2office

table2ppt: 导出统计输出到Microsoft Office PowerPoint/ LibreOffice Impress演示文稿中的表

table2doc: 将统计输出导出到Microsoft Office Word/ LibreOffice Writer文档中的表

table2office(x = NULL, file = "Rtable", type = c("PPT", "DOC"),

append = FALSE, digits = 2, digitspvals = 2, trim.pval = TRUE,

width = NULL, height = NULL, offx = 1, offy = 1,

font = ifelse(Sys.info()["sysname"] == "Windows", "Arial",

"Helvetica")[[1]], pointsize = 12, add.rownames = FALSE)

# Create a file name

filen # filen

# Generate ANOVA output

fit=aov(yield ~ block + N * P + K, data = npk) # 'npk' dataset from base 'datasets'

# Save ANOVA table as a PPT

### Option 1: pass output as object

x=summary(fit)

table2ppt(x=x,file=filen, digits = 1, digitspvals = 3, add.rownames =TRUE)

### Option 2: get output from console

summary(fit)

table2ppt(x=x,file=filen, width=5, font="Times New Roman", pointsize=14, digits=4, digitspvals=1, append=TRUE, add.rownames =TRUE) # append table to previous slide

# Save ANOVA table as a DOC file

table2doc(x=x,file=filen, digits = 1, digitspvals = 3, add.rownames =TRUE)

summary(fit)

table2doc(file=filen, width=3.5, font="Times New Roman", pointsize=14, digits=4, digitspvals=1, append=TRUE, add.rownames =TRUE) # append table at end of document

将表格数据导出到ppt和word中:

table2tex

table2html: 导出统计输出到HTML表。

table2tex(x = NULL, file = "Rtable", type = "TEX", digits = 2,

digitspvals = 2, trim.pval = TRUE, summary = FALSE, standAlone = TRUE,

add.rownames = FALSE, ...)

summary:是否汇总数据文件。

standAlone:导出的Latex代码应该是独立可编译的,还是应该粘贴到另一个文档中。

add.rownames:是否应该将行名添加到表中(在第一列之前插入一列)。

# Create a file name

filen # filen

# Generate ANOVA output

fit=aov(yield ~ block + N * P + K, data = npk) # 'npk' dataset from base 'datasets'

x=summary(fit)

# Export to Latex in standAlone format

table2tex(x=x,file=filen,add.rownames = TRUE)

# Export to Latex to paste in tex document

summary(fit) # get output from the console

table2tex(file=filen, standAlone = FALSE,add.rownames = TRUE)

# Export to HTML

table2html(x=x,file=filen) # or

summary(fit) # get output from the console

table2html(file=filen,add.rownames = TRUE)

导出到html或tex中的表格数据:

R统计和作图

Graphpad,经典绘图工具初学初探

维恩(Venn)图绘制工具大全 (在线+R包)

在R中赞扬下努力工作的你,奖励一份CheatShet

别人的电子书,你的电子书,都在bookdown

R语言 - 入门环境Rstudio

R语言 - 热图绘制 (heatmap)

R语言 - 基础概念和矩阵操作

R语言 - 热图简化

R语言 - 热图美化

R语言 - 线图绘制

R语言 - 线图一步法

R语言 - 箱线图(小提琴图、抖动图、区域散点图)

R语言 - 箱线图一步法

R语言 - 火山图

R语言 - 富集分析泡泡图

R语言 - 散点图绘制

R语言 - 韦恩图

R语言 - 柱状图

R语言 - 图形设置中英字体

R语言 - 非参数法生存分析

R语言 - 绘制seq logo图

WGCNA分析,简单全面的最新教程

psych +igraph:共表达网络构建

一文学会网络分析——Co-occurrence网络图在R中的实现

一文看懂PCA主成分分析

富集分析DotPlot,可以服

基因共表达聚类分析和可视化

R中1010个热图绘制方法

还在用PCA降维?快学学大牛最爱的t-SNE算法吧, 附Python/R代码

一个函数抓取代谢组学权威数据库HMDB的所有表格数据

文章用图的修改和排版

network3D:交互式桑基图

network3D 交互式网络生成

Seq logo 在线绘制工具——Weblogo

生物AI插图素材获取和拼装指导

ggplot2高效实用指南 (可视化脚本、工具、套路、配色)

图像处理R包magick学习笔记

SOM基因表达聚类分析初探

利用gganimate可视化全球范围R-Ladies(R社区性别多样性组织)发展情况

一分钟绘制磷脂双分子层:AI零基础入门和基本图形绘制

AI科研绘图(二):模式图的基本画法

你知道R中的赋值符号箭头(

R语言可视化学习笔记之ggridges包

利用ComplexHeatmap绘制热图(一)

ggplot2学习笔记之图形排列

R包reshape2,轻松实现长、宽数据表格转换

用R在地图上绘制网络图的三种方法

PCA主成分分析实战和可视化 附R代码和测试数据

iTOL快速绘制颜值最高的进化树!

12个ggplot2扩展包帮你实现更强大的可视化

编程模板-R语言脚本写作:最简单的统计与绘图,包安装、命令行参数解析、文件读取、表格和矢量图输出

R语言统计入门课程推荐——生物科学中的数据分析Data Analysis for the Life Sciences

数据可视化基本套路总结

你知道R中的赋值符号箭头和等号=的区别吗?

使用dplyr进行数据操作30例

交集intersect、并集union、找不同setdiff

R包reshape2,轻松实现长、宽数据表格转换

1数据类型(向量、数组、矩阵、 列表和数据框)

2读写数据所需的主要函数、与外部环境交互

3数据筛选——提取对象的子集

4向量、矩阵的数学运算

5控制结构

6函数及作用域

7认识循环函数lapply和sapply

8分解数据框split和查看对象str

9模拟—随机数、抽样、线性模型

1初识ggplot2绘制几何对象

2图层的使用—基础、加标签、注释

3工具箱—误差线、加权数、展示数据分布

4语法基础

5通过图层构建图像

6标度、轴和图例

7定位-分面和坐标系

8主题设置、存储导出

9绘图需要的数据整理技术

创建属于自己的调色板

28个实用绘图包,总有几个适合你

热图绘制

R做线性回归

绘图相关系数矩阵corrplot

相关矩阵可视化ggcorrplot

绘制交互式图形recharts

交互式可视化CanvasXpress

聚类分析factoextra

LDA分析、作图及添加置信-ggord

解决散点图样品标签重叠ggrepel

添加P值或显著性标记ggpubr

Alpha多样性稀释曲线rarefraction curve

堆叠柱状图各成分连线画法:突出组间变化

冲击图展示组间时间序列变化ggalluvial

桑基图riverplot

微生物环境因子分析ggvegan

五彩进化树与热图更配ggtree

多元回归树分析mvpart

随机森林randomForest分类Classification回归Regression

加权基因共表达网络分析WGCNA

circlize包绘制circos-plot

R语言搭建炫酷的线上博客系统

28个实用绘图包,总有几个适合你

热图绘制

R做线性回归

绘图相关系数矩阵corrplot

相关矩阵可视化ggcorrplot

绘制交互式图形recharts

交互式可视化CanvasXpress

聚类分析factoextra

LDA分析、作图及添加置信-ggord

解决散点图样品标签重叠ggrepel

添加P值或显著性标记ggpubr

Alpha多样性稀释曲线rarefraction curve

堆叠柱状图各成分连线画法:突出组间变化

冲击图展示组间时间序列变化ggalluvial

桑基图riverplot

微生物环境因子分析ggvegan

五彩进化树与热图更配ggtree

多元回归树分析mvpart

随机森林randomForest分类Classification回归Regression

加权基因共表达网络分析WGCNA

circlize包绘制circos-plot

R语言搭建炫酷的线上博客系统

维恩(Venn)图绘制工具大全 (在线+R包)

R包circlize:柱状图用腻了?试试好看的弦状图

获取pheatmap聚类后和标准化后的结果

增强火山图,要不要试一下?

一个震撼的交互型3D可视化R包 - 可直接转ggplot2图为3D

赠你一只金色的眼 - 富集分析和表达数据可视化

是Excel的图,不!是R的图

道友,来Rstudio里面看动画了

用了这么多年的PCA可视化竟然是错的!!!

易生信系列培训课程,扫码获取免费资料

更多阅读

画图三字经生信视频生信系列教程

心得体会TCGA数据库LinuxPython

高通量分析免费在线画图测序历史超级增强子

生信学习视频PPTEXCEL文章写作ggplot2

海哥组学可视化套路基因组浏览器

色彩搭配图形排版互作网络

自学生信影响因子GSEA单细胞

后台回复“生信宝典福利第一波”或点击

R plot图片背景设置为透明_万能转换:R图和统计表转成发表级的Word PPT Excel HTML Latex 矢量图等...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。