能转换:R图和统计表转成发表级的Word、PPT、Excel、HTML、Latex、矢量图等
R包export可以轻松的将R绘制的图和统计表输出到 Microsoft Office (Word、PowerPoint和Excel)、HTML和Latex中,其质量可以直接用于发表。
export包可以在Windows、Ubuntu和Mac上跨平台运行。不过有些Mac发行版默认情况下没有安装cairo设备,需要自行安装。如果Mac用户已安装XQuartz,这个问题就解决了,它可以从https://www.xquartz.org/免费获得。
install.packages("export")
install.packages("officer")
install.packages("rvg")
install.packages("openxlsx")
install.packages("ggplot2")
install.packages("flextable")
install.packages("xtable")
install.packages("rgl")
install.packages("stargazer")
install.packages("tikzDevice")
install.packages("xml2")
install.packages("broom")
install.packages("devtools")
devtools::install_github("tomwenseleers/export")
该包主要包括以下几种转换
使用帮助信息如下:
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, ...)
安装完 export包后,先调用该包
library(export)
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,versicolour或virginica)。每个花的特征用下面的5种属性描述萼片长度(Sepal.Length)、萼片宽度(Sepal.Width)、花瓣长度(Petal.Length)、花瓣宽度(Petal.Width)、类(Species)。
在console里展示数据图 (长宽比自己调节):
# 需运行上面的ggplot2绘图
# Create a file name
# 程序会自动加后缀
filen <- "output_filename" # or
# filen <- paste("YOUR_DIR/ggplot")
# 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 <- function(){
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)
转换后的图形:
大部分图的细节修改都是用代码完成的,不需要后续的修饰;但如果某一些修改比较特异,不具有程序的通用性特征,或实现起来比较困难,就可以考虑后期修改。比如用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, ...)
# 需运行上面的ggplot2绘图
# Create a file name
filen <- "output_filename" # or
# filen <- paste("YOUR_DIR/ggplot")
# 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)
函数参数解释
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, ...)
#需运行上面的ggplot2绘图
# Create a file name
filen <- "output_filename" # or
# filen <- paste("YOUR_DIR/ggplot")
# 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")
rgl2png: 将当前的rgl 3D图形保存为PNG格式。
rgl2bitmap(file = "Rplot", type = c("PNG"))
# Create a file name
filen <- tempfile("rgl") # or
# filen <- paste("YOUR_DIR/rgl")
# 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(x = NULL, file = "Rtable", type = c("XLS", "CSV",
"CSV2"), append = FALSE, sheetName = "new sheet", digits = 2,
digitspvals = 2, trim.pval = TRUE, add.rownames = FALSE, ...)
# Create a file name
filen <- "table_aov" # or
# filen <- paste("YOUR_DIR/table_aov")
# 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)中表格数据:
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 <- "table_aov"
# filen <- paste("YOUR_DIR/table_aov")
# 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中:
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 <- tempfile(pattern = "table_aov") # or
# filen <- paste("YOUR_DIR/table_aov")
# 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中的表格数据:
wf 是国外某公司的动画设计软件 Flash 专用格式。白话一点,swf 文件是 Flash 软件或者 animate 软件导出时的一种特殊的视频格式,最常应用的场景是网页 html 设计中,现在用得不多。
所以很多软件不兼容此格式,无法播放这类格式的视频。下面小编教大家三种方法将 swf 格式转换成 mp4 格式。
推荐指数:☆☆☆☆☆
目前市面上有各种各样的视频转码软件,既有付费的,也有免费的工具,无论是付费还是免费的,小编觉得最主要的是能否转换,转换之后是否会影响到视频的质量,如视频分辨率、音视频是否同步等。下面以野葱视频转换器为例,为大家讲解一下。
这是一款多功能的视频格式转换软件,它支持各种格式的视频音频文件转换,并且操作简单,即使是零基础的电脑小白也能够在短时间内学会操作,快速上手!下面就让我们来看看该软件具备什么特色吧!
1、支持丰富的文件格式
MP4、AVI、MKV、FLV、WMV、M4V、MOV等上百种视频格式,并且支持自定义分辨率,如1080P、720P、4K等;
2、操作简单、转换效率高
借助这款工具如何实现格式转换?四步操作就能够帮你搞定:【选择功能-上传文件-设置参数-转换完成】。另外这款软件还支持批量转换,能够一次上传多个视频进行转换操作,提高效率的同时也节省了不少时间。
3、功能丰富
除了视频格式转换之外,它还支持视频分割合并、视频转GIF、视频水印、视频优化、视频压缩等功能。经常需要编辑视频文件的小伙伴们有福了,用它就能够实现很多操作哦!
推荐指数:☆☆☆
有一些小伙伴觉得电脑操作比较麻烦,目前市面上同样有一些视频转码的平台可以在线处理,只是多数是国外的网站,可以转换速度比较慢。
步骤 1:浏览器打开 Online-Convert,选择对应的功能;
步骤 2:点击中间那个云朵的箭头,上传需要转换的视频文件,下方是一些参数的设置,大家可以根据自己的需求选择对应的参数;
步骤 3:视频转换完成后,会自动保存到本地,一般会在本地的「下载」中。
推荐指数:☆☆☆
VLC media Player 是一款国外的开源跨平台多媒体播放器,可以兼容绝大多数市面上的视频文件格式,由于存在一定技术门槛,所以不太适合小白用户。
步骤 1:运行软件 VLC media Player,进入软件后点击「Media」-「Convert/Save」;
步骤 2:点击右侧的「add」按钮添加需要转换的视频文件,上传成功后,左侧的界面内会罗列出相关的视频信息;
步骤 3:添加成功后设置好输出格式、存储路径等相关参数,点击「Start」即转换。
以上就是分享给大家的「swf怎么转换成mp4格式」三种方法,以及详细的swf转换成mp4的详细操作步骤,你们都学会了吗~
么把swf文件转换mp4?小编在百度百科上看到的解释是,swf 是国外公司的动画设计软件 Flash 专用格式。说白了就是,swf文件是Flash软件或者 animate软件导出时的一种视频格式,常用场景是再网页html设计中,这是一种专属于动画设计的格式,对于经常在网页设计这块的小伙伴们来说应该最为熟悉了。想要打开swf格式就必须在浏览器中装上flash插件才能进行播放,对于非设计专业的小伙伴们使用起来就不是很熟悉了,会显得很麻烦。
swf是一种flash动画生成格式,所以很多软件不兼容此格式,无法播放这类格式的视频。有时电脑里面如果没有安装相关的插件也无法打开。所以在这里面有个方法就是将swf格式转换成常用的MP4,mp4格式兼容性也比较好,我们使用起来会更方便一些,这样在工作和学习中使用起来就没有那么复杂了,如何将swf转换成mp4呢,小编给小伙伴们分享了一种好用的转换方法,下面让我们来看看详细的使用步骤。
swf转mp4需借助工具:优速视频处理大师
工具下载地址:https://download.yososoft.com/YSVideos/YSVideos_TTY.exe
swf转换mp4格式的操作:
步骤1、打开电脑中的软件“优速视频处理大师”,在首页面中选择所要用到的【格式转换】功能。如果大家电脑上没有这款软件,就需要我们去下载并安装一下
步骤2、然后点击【添加文件】按钮,选择需要转换的swf视频文件上传到软件中,当然也可以用鼠标直接将其拖拽到软件中,软件支持批量格式转换,对上传的文件个数不限制。
步骤3、文件上传完成后,在右侧格式下拉框中将转换后的视频格式选择成为MP4,接着设置输出目录,用来保存转换好的MP4文件。
步骤4、上述设置妥当后,点击【开始转换】按钮,这样软件就开启了格式转换功能。并在转换结束后自动弹出输出文件夹,方便用户查看文件。
步骤5、最后我们将转换前后的视频文件进行对比,如下图所示,很明显看到上传时的swf文件变成了现在的MP4视频文件,那说明软件转换很成功。
以上就是swf怎么转换成mp4的全部操作过程了,是不是很简单学起来也很方便,通过上面的这几个步骤,很快捷地就能将视频的格式进行转换,既简单又方便,节省了我们很多时间,大家有需求的也可以去试一试。好了我们下期再见!
*请认真填写需求信息,我们会在24小时内与您取得联系。