相關(guān)的例子) 。
鳶尾花(iris)是數(shù)據(jù)挖掘常用到的一個(gè)數(shù)據(jù)集,包含150個(gè)鳶尾花的信息,每50個(gè)取自三個(gè)鳶尾花種之一(setosa,versicolour或virginica) 。每個(gè)花的特征用下面的5種屬性描述萼片長(zhǎng)度(Sepal.Length)、萼片寬度(Sepal.Width)、花瓣長(zhǎng)度(Petal.Length)、花瓣寬度(Petal.Width)、類(Species) 。
在console里展示數(shù)據(jù)圖 (長(zhǎng)寬比自己調(diào)節(jié)):
導(dǎo)出圖形對(duì)象# 需運(yùn)行上面的ggplot2繪圖# Create a file name# 程序會(huì)自動(dòng)加后綴filen <- "output_filename" # or# filen <- paste("YOUR_DIR/ggplot")# There are 3 ways to use graph2bitmap():### 1. Pass the plot as an objectgraph2png(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)
導(dǎo)出當(dāng)前繪圖窗口展示的圖### 2. Get the plot from current screen device# 注意這個(gè)x,是運(yùn)行命令,展示圖像xgraph2png(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)
導(dǎo)出自定義函數(shù)輸出的一組圖### 3. Pass the plot as a functioplot.fun <- function(){print(qplot(Sepal.Length, Petal.Length, data = https://www.520longzhigu.com/shenghuo/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)
轉(zhuǎn)換后的圖形:
與Office系列的交互大部分圖的細(xì)節(jié)修改都是用代碼完成的,不需要后續(xù)的修飾;但如果某一些修改比較特異,不具有程序的通用性特征,或?qū)崿F(xiàn)起來(lái)比較困難,就可以考慮后期修改 。比如用AI文章用圖的修改和排版 。熟悉PPT的,也可以用PPT,這時(shí)R的圖導(dǎo)出PPT,就要用到graph2office系列函數(shù)了 。
graph2ppt: 將當(dāng)前R圖保存到Microsoft Office PowerPoint/LibreOffice Impress演示文稿中 。
graph2doc:將當(dāng)前的R圖保存到Microsoft Office Word/LibreOffice Writer文檔中 。
函數(shù)參數(shù)展示和解釋
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: 預(yù)設(shè)留白邊距向量 。
- paper: 紙張尺寸——“A5”至“A1”用于Powerpoint導(dǎo)出,或“A5”至“A3”用于Word輸出;默認(rèn)“auto”自動(dòng)選擇適合您的圖形的紙張大小 。如果圖太大,無(wú)法在給定的紙張大小上顯示,則按比例縮小 。
- orient: 所需的紙張方向-“自動(dòng)”,“縱向”或“橫向”; Word輸出默認(rèn)為“自動(dòng)”,Powerpoint默認(rèn)為“橫向” 。
- vector.graphic: 指定是否以可編輯的向量DrawingML格式輸出 。默認(rèn)值為T(mén)RUE,在這種情況下,編輯Powerpoint或Word中的圖形時(shí),可以先對(duì)圖形元素進(jìn)行分組 。如果設(shè)置為FALSE,則將該圖以300 dpi的分辨率柵格化為PNG位圖格式 。(柵(shān)格化,是PS中的一個(gè)專業(yè)術(shù)語(yǔ),柵格即像素,柵格化即將矢量圖形轉(zhuǎn)化為位圖 。)
# 需運(yùn)行上面的ggplot2繪圖# Create a file namefilen <- "output_filename" # or# filen <- paste("YOUR_DIR/ggplot")# There are 3 ways to use graph2office():### 1. Pass the plot as an object# 導(dǎo)出圖形對(duì)象graph2ppt(x=x, file=filen)graph2doc(x=x, file=filen, aspectr=0.5)### 2. Get the plot from current screen device# 導(dǎo)出當(dāng)前預(yù)覽窗口呈現(xiàn)的圖xgraph2ppt(file=filen, width=9, aspectr=2, append = TRUE)graph2doc(file=filen, aspectr=1.7, append =TRUE)### 3. Pass the plot as a function# 導(dǎo)出自定義函數(shù)輸出的一系列圖graph2ppt(fun=plot.fun, file=filen, aspectr=0.5, append = TRUE)graph2doc(fun=plot.fun, file=filen, aspectr=0.5, append = TRUE)
以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問(wèn)題,請(qǐng)您及時(shí)就醫(yī)或請(qǐng)專業(yè)人士給予相關(guān)指導(dǎo)!
「愛(ài)刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對(duì)您有所幫助:
- PDF轉(zhuǎn)換成Excel的方法 PDF如何轉(zhuǎn)換成EXCEL
- 南方立秋吃什么 立秋養(yǎng)生吃什么好
- 如何防蚊蟲(chóng)叮咬 夏天防蚊蟲(chóng)的方法
- 秋冬季如何養(yǎng)生 秋冬季健康養(yǎng)生方法
- 夏季如何養(yǎng)生 夏季養(yǎng)生飲食小常識(shí)
- 冬季御寒措施 冬季如何保暖御寒
- 天冷吃什么食物好 什么茶適合天冷喝
- 圖文 屬鼠都是怎么看待抑郁癥患者的
- 圖文 關(guān)燈后 屬鼠女生最喜歡跟男友聊什么
- 圖文 最讓屬鼠在生活中感覺(jué)到驕傲的時(shí)候
