R语言统计数据范围并用ggplot2绘制饼图的方法

发布时间:2022-01-20 10:40:20 作者:iii
来源:亿速云 阅读:311

这篇文章主要介绍了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绘制饼图的方法”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. canvas如何绘制饼图
  2. 怎么用R语言绘制饼图和条形图

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

r语言 ggplot2

上一篇:激活win10工具怎么用

下一篇:Html5+JS如何实现手机摇一摇功能

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》