R画饼图
2020-03-31 本文已影响0人
落寞的橙子
对Signature组计算每个项目对占比并画图,使用ggpubr包
rm(list=ls())
suppressMessages(library(ggpubr))
suppressMessages(library(tidyverse))
suppressMessages(library(vcd))
opposite_cor_dir="/data_dir"
combine_cor<-read.csv(paste0(opposite_cor_dir,"/data.csv"),header = T)
signature<-with(combine_cor,table(Signature))
signature<-as.data.frame(prop.table(signature)*100)
#加上%,并保留两位,新建新的列Freq
signature$"labs"<-sapply(as.character(round(signature$Freq,digits = 2)),function(x){return(paste0(x,"%"))})
p<-ggpie(signature,"Freq",
label = "labs",
lab.pos = "out", lab.font = "white",
fill = "Signature",
color = "white",
palette = c("#0A5EB9","#d4ccd4","#727272","#DF3D8C"))
pie_filename<-"~/out_dir/pieplot.pdf"
ggsave(filename =pie_filename,p,height = 7,width = 8,device = "pdf",units="in")