参考文章
我的例子
原始数据如下:
要先把数据进行线性化,使用gather来实现,代码如下:
rm(list=ls())
suppressMessages(library(tidyverse))
suppressMessages(library(ggpubr))
lnc_overlap_list<-lnc_overlap %>% gather(value = "all")
dlast <- table(cut(lnc_overlap_list$all, breaks = c(0,5,15,20,25,30,35,40)))
dlast1 <- as.vector(dlast)
dlast2 <- round(dlast1/nrow(lnc_overlap_list), digits = 6)
dlast3 <- paste(dlast2*100, "%")
dl <- data.frame(dimnames(dlast),dlast1,dlast2*100, dlast3)
colnames(dl)<-c("Group","Number","Precentage","Labs")
dl$Precentage<-as.numeric(dl$Precentage)
dl$"Group"<-as.factor(c("0-5 %","6-10 %","11-15 %","16-20 %","21-25 %","26-30 %","31-35 %","36-40 %"))
dir="~/your_dir"
dir.create(lncRNA_overlap_dir,recursive = T)
overlap_filename<-paste0(ldir,"/pie.pdf")
pdf(file =overlap_filename,height = 7.2,width = 8.2)
dl$Group <- factor(dl$Group, levels=unique(dl$Group))
p<-ggpie(dl,"Precentage",
label = "Labs",
lab.pos = "out", lab.font = "white",
fill = "Group",
color = "white",
palette = "jco")
plot(p)
dev.off()
统计频数方法2
参考文章
网友评论