【问题标题】:Add percentage (%) for a PieChart为饼图添加百分比 (%)
【发布时间】:2021-08-26 00:56:33
【问题描述】:

大家好,我正在尝试制作如下图所示的饼图: 但是我遇到了很多问题

但这是我得到的情节:

ggpie(s, x="costes", label ="prop", lab.pos = "in", fill = "Implementation",
  lab.font = list(size= 5)) + scale_fill_manual(values = c("dodgerblue2","blue"))

如何在我的标签中添加百分比,例如 98.9%...等

数据: structure(list(Implementation = c("2", "1"), costes = c(6204670582.33, 70561379.07), prop = c(98.9, 1.1), lab.ypos = c(49.45, 99.45)), row.names = c(NA, -2L), class = c("tbl_df", "tbl", "data.frame"))

非常感谢您的宝贵时间

【问题讨论】:

    标签: r ggplot2 pie-chart


    【解决方案1】:
    per <- c(0.1,0.2,0.3,0.4)
    labels <- c("a","b","c","d")
    pie(per,labels = paste0(labels," (",round(per,digits = 3)*100,"%)"),
        border="white",col = c("red","green","blue","yellow"))
    

    【讨论】:

      【解决方案2】:

      您可以使用 'labels = ' 添加。我将您的数据命名为虚拟对象。

      > dummy
      # A tibble: 2 x 4
        Implementation      costes  prop lab.ypos
        <chr>                <dbl> <dbl>    <dbl>
      1 2              6204670582.  98.9     49.4
      2 1                70561379.   1.1     99.4
      
      
      
      dummy %>%
        ggpie(x="costes", label ="prop", lab.pos = "in", fill = "Implementation",
              lab.font = list(size= 5)) + 
        scale_fill_manual(values = c("dodgerblue2","blue"), 
                          labels = paste(dummy$Implementation, (dummy$prop)))
      

      【讨论】:

        猜你喜欢
        • 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
        相关资源
        最近更新 更多