【问题标题】:Showing counts and percentages in echarts4r `e_pie` pie charts在 echarts4r `e_pie` 饼图中显示计数和百分比
【发布时间】:2021-02-27 15:34:16
【问题描述】:

我想在 echarts4r 的 e_pie 创建的圆环图中绘制计数和/或百分比。

这是文档的link

以下是文档中的示例,生成了以下没有计数和百分比的圆环图:

mtcars %>% 
  head() %>% 
  dplyr::mutate(model = row.names(.)) %>% 
  e_charts(model) %>% 
  e_pie(carb, radius = c("50%", "70%")) %>% 
  e_title("Donut chart")

我正在寻找的是从 R plotly 中实现的这样的东西:

mtcars %>% 
  head() %>% 
  dplyr::mutate(model = row.names(.)) %>% 
  plot_ly(labels = ~ model,
                    values = ~ carb,
                    textinfo = 'value+percent',
                    marker = list(colors = c("#ABDDDE","#F8AFA8"),
                                  line = list(color = '#000000',
                                              width = 0.75)
                                  )
          ) %>%
    add_pie(hole = 0.6) %>%
    layout(title = " Donut chart", showlegend = T)

【问题讨论】:

    标签: r echarts echarts4r


    【解决方案1】:

    您可以使用e_labels 定义标签并将文本与e_titlee_legend 对齐:

    mtcars %>% 
      head() %>% 
      dplyr::mutate(model = row.names(.)) %>% 
      e_charts(model) %>% 
      e_pie(carb, radius = c("50%", "70%"))  %>% 
      e_title("Donut chart",
              textAlign  = "center",
              left ="50%") %>%
      e_labels(show = TRUE,
               formatter = "{c} \n {d}%",
               position = "inside") %>%
      e_legend(right = 0, 
               orient = "vertical")
    

    在文档中,格式化程序 {c} 和 {d} 被列为

    {c}:数据项的值。
    {d}:百分比。

    【讨论】:

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