您好,登錄后才能下訂單哦!
這篇文章主要介紹了R語言統計數據范圍并用ggplot2繪制餅圖的方法的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇R語言統計數據范圍并用ggplot2繪制餅圖的方法文章都會有所收獲,下面我們一起來看看吧。
統計數據,以及ggplot2繪圖餅圖代碼如下:
library(reshape2) local({r <- getOption("repos") ;r["CRAN"] <- "http://mirrors.tuna.tsinghua.edu.cn/CRAN/" ;options(repos=r)}) library(ggplot2) library(cowplot) library(RColorBrewer) pairjoinC <- function(x,y){ ran1=paste(paste(head(x,-1),"%",sep=""), paste(tail(x,-1),"%",sep=""), sep="-") ran1[length(ran1)]=">40%" ran1=paste(ran1," (",y,")",sep="") ran1 } # use the base hist() function to calculate BINs ,超過40%的統計到一起; data[data>40]=41 MassStatC <- with(hist(data, breaks=seq(0, 45, by = 5), plot=FALSE), data.frame(N=counts, Mass=pairjoinC(breaks,counts), PCT=counts/sum(counts))) MassStatC$Mass=factor(MassStatC$Mass, levels=rev(MassStatC$Mass), order=T) pe = ggplot(MassStatC, aes(x="", y= N, fill= Mass))+ geom_bar(stat="identity",width=1)+ coord_polar(theta="y")+ labs(x="", y="",title="Distribution of Protein's Sequence Coverages")+ theme(axis.ticks = element_blank(), axis.text.x = element_blank())+ scale_fill_brewer(palette="Paired",breaks = MassStatC$Mass, labels = as.character(MassStatC$Mass),direction=-1)+ geom_text(aes(x = 1.7, y = cumsum(MassStatC$N)-MassStatC$N/2 , label =paste( as.character(round(MassStatC$PCT*100,2)),"%",sep="")), show.legend = FALSE, color="black")+ theme(plot.title = element_text(hjust = 0.5), legend.title = element_blank(), panel.background = element_rect(fill = "transparent",colour = NA), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), axis.line= element_blank(), plot.background = element_rect(fill = "transparent",colour = NA)) pe
關于“R語言統計數據范圍并用ggplot2繪制餅圖的方法”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“R語言統計數據范圍并用ggplot2繪制餅圖的方法”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。