
image.png
1. 安装对应的eoffice包:
install.packages("eoffice") # 安装包
library(eoffice) # 加载包
library(readxl)#读取数据所用
library(ggplot2)#绘制图片
所用的数据格式:
Samples percent
Sample1 12
Sample2 21
Sample3 13
Sample4 14
Sample5 76
Sample6 12
Sample7 86
Sample8 28
Sample9 36
存于excel,并用readxl包读取:
library(readxl)
df1<-as.data.frame(read_xlsx(file.choose()))
df

image.png
2. 作图1和存储到figure1.pptx:
library(ggplot2)
if(interactive()){
## use ggplot2 to create figure
gp1<-ggplot(df1,aes(x=Samples,y=percent))+
geom_point(aes(fill=Samples))+
theme_bw() +labs(x="Sample Names",y="Percentage")+
theme(legend.position = "none")
# save the figure in a pptx
topptx(figure=gp1,filename = "C:/Users/Mr.R/Desktop/figure1.pptx",width = 3,height = 4)# create a pptx file on desktop
}
在桌面得到figure1.pptx文件,存储了刚做的图片gp1(可以用组合工具搞定图片格式的调整)。

image.png
3. 作图2和存储到figure2.pptx:
library(ggplot2)
if(interactive()){
## use ggplot2
library(ggplot2)
gp2<-ggplot(df1,aes(x=Samples,y=percent))+
geom_col(aes(fill=Samples))+
theme_bw()+coord_flip()+labs(x="Sample Names",y="Percentage")+
theme(legend.position = "none")
# save the figure in a pptx
topptx(figure=gp2,filename = "C:/Users/Mr.R/Desktop/figure2.pptx",width = 3,height = 4)# create a pptx file on desktop with determined size
}
在桌面得到figure2.pptx文件,存储了刚做的图片gp2(可以用组合工具搞定图片格式的调整)。

image.png
3. 用ppt编辑图片:选择图片---右键---组合---取消组合--
对自己需要的文字等部分进行编辑。

image.png
网友评论