【问题标题】:Faceted Pie Charts分面饼图
【发布时间】:2018-05-10 06:18:50
【问题描述】:

我在使用多面饼图时遇到问题。

这是我的数据集的头部。

> head(pie)

          piper         prop      bat
1  P. sancti-felicis 0.617593433  Cs
2     P. reticulatum 0.617593433  Cs
3       P. colonense 0.069142205  Cs
4 P. multiplinervium 0.007650765  Cs
5        P. peltatum 0.006790803  Cs
6       P. umbricola 0.102377661  Cs

这是我正在尝试的代码...

a <- ggplot(pie, aes(x = piper,y=prop, fill = piper)) +
+   geom_bar(width = 1,stat='identity')
b <- a + coord_polar(theta = "y", start = 0, direction = 1)
b + facet_grid(facets=. ~ bat)

当我想显示一个按颜色分隔吹笛者的常规饼图时,它似乎显示在一个 coxcomb 饼图中。三个饼图被 bat 正确分隔。非常感谢您的建议!

【问题讨论】:

    标签: r ggplot2 pie-chart


    【解决方案1】:

    如果您能提供整个数据集或它的虚构/简化版本(另请参阅 here),将会有很大帮助。否则很难弄清楚到底是什么问题,甚至一开始就很难弄清楚这个数字应该是什么样子。

    无论如何,我正在处理您提供的六行数据:

    df <- read.table(text = "piper         prop      bat
      'P. sancti-felicis' 0.617593433  Cs
         'P. reticulatum' 0.617593433  Cs
           'P. colonense' 0.069142205  Cs
     'P. multiplinervium' 0.007650765  Cs
            'P. peltatum' 0.006790803  Cs
           'P. umbricola' 0.102377661  Cs", header = TRUE)
    
    #               piper        prop bat
    #1  P. sancti-felicis 0.617593433  Cs
    #2     P. reticulatum 0.617593433  Cs
    #3       P. colonense 0.069142205  Cs
    #4 P. multiplinervium 0.007650765  Cs
    #5        P. peltatum 0.006790803  Cs
    #6       P. umbricola 0.102377661  Cs
    

    一个直接的问题是比例不相加,所以不清楚你想如何在饼图中绘制它们。然而,忽略这个问题,我们可以假设比例没有标准化,我们需要自己标准化它们(通过除以比例的总和)。如果这是正确的,那么我们可以画一个这样的饼图:

    ggplot(df, aes(x = 1, y = prop, fill = piper)) + 
      geom_col(position = "stack") + facet_wrap(~bat) +
      coord_polar(theta = "y") + theme_minimal()
    

    我用 bat 进行了分面,但由于我的数据集中只有一个,因此结果中只有一个 pie。我还使用theme_minimal() 去除了大部分令人分心的灰色背景等,但你可以使用任何你喜欢的主题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多