能轉換: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小時內與您取得聯系。