在 echarts4r `e_pie` 饼图中显示计数和百分比
Showing counts and percentages in echarts4r `e_pie` pie charts
我想在 e_pie
从 echarts4r 创建的圆环图中绘制计数 and/or 百分比。
这是文档的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)
您可以使用 e_labels
定义标签,并使用 e_title
和 e_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}: the value of a data item.
{d}: the percent.
我想在 e_pie
从 echarts4r 创建的圆环图中绘制计数 and/or 百分比。
这是文档的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)
您可以使用 e_labels
定义标签,并使用 e_title
和 e_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}: the value of a data item.
{d}: the percent.