欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

如何用R語言ggplot2畫環(huán)狀柱形圖

這篇文章主要介紹“如何用R語言ggplot2畫環(huán)狀柱形圖”,在日常操作中,相信很多人在如何用R語言ggplot2畫環(huán)狀柱形圖問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”如何用R語言ggplot2畫環(huán)狀柱形圖”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都網(wǎng)站建設、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的景洪網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設合作伙伴!


偶然間找到了一份教程利用ggplot2繪制環(huán)狀柱形圖,個人感覺非常適合用來展示葉綠體基因組蛋白編碼基因的dn/ds值,因為不僅能夠通過柱狀圖的高低來比較dn/ds值的大小,還能夠通過環(huán)狀展示蛋白編碼基因在葉綠體基因組上所處的位置

A circular barplot is a barplot where bars are displayed along a circle instead of a line.

 簡易版的環(huán)狀柱形圖 就是這樣似的
如何用R語言ggplot2畫環(huán)狀柱形圖  
 接下來重復教程

https://www.r-graph-gallery.com/297-circular-barplot-with-groups/

 代碼
#準備數(shù)據(jù)
df<-data.frame(individual=paste("Mister",seq(1,60),sep=""),value=sample(seq(10,100),60,replace=T))
df$id<-seq(1,nrow(df))
library(ggplot2)
#簡易柱形圖
p<-ggplot(df,aes(x=as.factor(id),y=value))+geom_bar(stat="identity",fill=blue)#目前還是不太清楚stat參數(shù)的作用
 
如何用R語言ggplot2畫環(huán)狀柱形圖  
Rplot06.png
#簡易環(huán)狀柱形圖
p+coord_polar()
 
如何用R語言ggplot2畫環(huán)狀柱形圖  
Rplot05.png
 環(huán)狀圖中間搞成空心,看起來好像美觀一點
p+ylim(-100,120)+coord_polar()
#添加標簽
p+coord_polar()+ylim(-100,120)+
  geom_text(aes(x=id,y=value+20,label=individual),size=3)+
  theme_minimal()+ylab("")+
  theme(axis.text.x = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank())
 
如何用R語言ggplot2畫環(huán)狀柱形圖  
Rplot07.png

標簽看起來有些亂,自己沒有想到解決辦法,模仿教程中的解決辦法:為參數(shù)hjust和angle賦予數(shù)據(jù)來調控標簽的位置

df$angle<-96-df$id*6
ggplot(df,aes(x=as.factor(id),y=value))+
  geom_bar(stat="identity",fill=alpha("blue",0.7))+
  coord_polar()+ylim(-100,120)+
  geom_text(aes(x=id,y=value+20,label=individual,angle=angle),
            size=3,hjust=0.2)+
  theme_minimal()+ylab("")+xlab("")+
  theme(axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.x = element_blank())
 
如何用R語言ggplot2畫環(huán)狀柱形圖  
Rplot08.png
#在完善一下
df$angle1<-ifelse(df$id<=30,96-df$id*6,96-df$id*6+180)
df$hjust<-ifelse(df$id<=30,0.2,1)
ggplot(df,aes(x=as.factor(id),y=value))+
  geom_bar(stat="identity",fill=alpha("blue",0.7))+
  coord_polar()+ylim(-100,120)+
  geom_text(aes(x=id,y=value+20,label=individual,
                angle=angle1,hjust=hjust),size=3)+
  theme_minimal()+ylab("")+xlab("")+
  theme(axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.x = element_blank(),
        panel.grid = element_blank())
 
如何用R語言ggplot2畫環(huán)狀柱形圖  
Rplot09.png

葉綠體基因組通常是典型的四部分結構,如何把上圖改成四部分然后添加四種不同的顏色,原教程提供的解決辦法是添加缺失值,畫圖時就會出現(xiàn)空白的部分從而達到分割的目的

df1<-data.frame(individual=paste("Mister",seq(1,60),sep=""),
                value=rep(c(sample(60:100,9,replace=T),NA),6))
df1$id<-seq(1,nrow(df1))
df1
df1$angle<-df$angle1
df1$hjust<-df$hjust
df1
df1$fill<-c(rep("A",10),rep("B",10),rep("C",10),rep("D",10),rep("E",10),rep("F",10))
ggplot(df1,aes(x=as.factor(id),y=value))+
  geom_bar(stat="identity",aes(fill=fill))+
  coord_polar()+ylim(-100,120)+
  geom_text(aes(x=id,y=value+20,label=individual,
                angle=angle,hjust=hjust),size=3)+
  theme_minimal()+ylab("")+xlab("")+
  theme(axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.x = element_blank(),
        panel.grid = element_blank(),
        legend.position="none")+
  scale_fill_manual(values=c("red","yellow","blue","green","orange","skyblue"))

 
如何用R語言ggplot2畫環(huán)狀柱形圖  
Rplot10.png

######小知識點:ggplot2更改繪圖區(qū)空白大小 https://ggplot2.tidyverse.org/reference/element.html

theme(plot.margin=unit(c(1,1,1,1),'cm'))
#更改里面的數(shù)值即可
#比如可以比較一下以下兩條命令的區(qū)別
df<-data.frame(A=1:10,B=10:1)
p<-ggplot(df,aes(x=A,y=B))+geom_point()
p+theme(plot.margin=unit(1,1,1,1),'cm')
p+theme(plot.margin=unit(2,2,2,2),'cm')

到此,關于“如何用R語言ggplot2畫環(huán)狀柱形圖”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

本文名稱:如何用R語言ggplot2畫環(huán)狀柱形圖
分享網(wǎng)址:http://www.chinadenli.net/article36/igpjpg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作網(wǎng)站策劃移動網(wǎng)站建設響應式網(wǎng)站云服務器網(wǎng)站設計

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

h5響應式網(wǎng)站建設