ggplot2 中饼图大小可变的饼图 [英] Pie charts in ggplot2 with variable pie sizes

查看:71
本文介绍了ggplot2 中饼图大小可变的饼图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了各种方法来获取 ggplot2 中饼图的 facet_grid 以根据另一个变量(强度)改变宽度/半径.

I've tried various ways to get a facet_grid of pie charts in ggplot2 to vary width/radii according to another variable (strength).

geom_bar 接受 width=0.5 作为参数,但一旦添加了 coord_polar,它就会被忽略.将 width=0.5 添加到 ggplot aes 或将 aes 添加到 geom_bar 不起作用.我看不到 coord_polar 的任何其他相关选项.什么是最简单的方法来做到这一点?下面的代码制作了一个很好的饼图网格,但不会改变饼图的大小.我错过了什么?

geom_bar accepts width=0.5 as a parameter but it is ignored once coord_polar is added. Adding width=0.5 to the ggplot aes or adding a aes to geom_bar doesn't work. I can't see any other relevant options for coord_polar. What's the easiest way to do this? The code below makes a nice grid of pie charts but doesn't change the sizes of the pie charts. What am I missing?

mydata <- data.frame(side1=rep(LETTERS[1:3],3,each=9),side2=rep(LETTERS[1:3],9,each=3),widget=rep(c("X","Y","Z"),9*3),val=runif(9*3),strength=rep(c(1,2,3),3,each=3))
ggplot(mydata, aes(x="",y = val, fill = widget, width = strength)) +
geom_bar(position="fill") + facet_grid(side1 ~ side2) +
coord_polar("y") + opts(axis.text.x = theme_blank()) 

推荐答案

你的意思是这样吗?

ggplot(mydata, aes(x=strength/2, y = val, fill = widget, width = strength)) +
  geom_bar(position="fill", stat="identity") + 
  facet_grid(side1 ~ side2) + 
  coord_polar("y") + 
  opts(axis.text.x = theme_blank()) 

这篇关于ggplot2 中饼图大小可变的饼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆