您好,登錄后才能下訂單哦!
這篇文章主要介紹了R語言統(tǒng)計(jì)數(shù)據(jù)范圍并用ggplot2繪制餅圖的方法的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇R語言統(tǒng)計(jì)數(shù)據(jù)范圍并用ggplot2繪制餅圖的方法文章都會(huì)有所收獲,下面我們一起來看看吧。
統(tǒng)計(jì)數(shù)據(jù),以及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%的統(tǒng)計(jì)到一起; 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
關(guān)于“R語言統(tǒng)計(jì)數(shù)據(jù)范圍并用ggplot2繪制餅圖的方法”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“R語言統(tǒng)計(jì)數(shù)據(jù)范圍并用ggplot2繪制餅圖的方法”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。