【问题标题】:Exploded 180 degree pie chart in R ggplot or ggvis (image included)?R ggplot 或 ggvis 中的爆炸 180 度饼图(包括图像)?
【发布时间】:2016-06-05 16:40:31
【问题描述】:

给定一个包含因子列 (X1) 和小计列 (X2) 的数据集

  X1 X2 
1  1  12  
2  2  200 
3  3  23  
4  4  86  
5  5  141  

我想创建一个这样的图形:

x2 占 X2 总数的百分比除以 X1。

编辑:清晰并添加数据集以实现可重复性

【问题讨论】:

  • 请阅读有关how to ask a good question 的信息以及如何提供reproducible example。就目前的问题而言,它可以被视为工具/教程请求,这是投票结束的原因。
  • 当然,我已经进行了编辑以更好地适应。这有帮助吗?

标签: r plot ggplot2 visualization ggvis


【解决方案1】:

例如

set.seed(1234)
df <- data.frame(x = 1:6)
df$y <- runif(nrow(df))
df$type <- sample(letters, nrow(df))
ggplot(df, aes(x+-.5, y, fill=type)) + 
  geom_bar(stat="identity", width=1) + 
  coord_polar(start = pi/2) + 
  scale_x_continuous(limits = c(0, nrow(df)*2)) + 
  geom_text(aes(label=scales::percent(y))) + 
  ggthemes::theme_map() + theme(legend.position = c(0,.15))

给你

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-26
    • 2014-02-04
    • 1970-01-01
    • 2017-02-26
    相关资源
    最近更新 更多