Reputation: 287
I would like to plot the counts and/or percentages in a donut chart created by e_pie
from echarts4r.
This is the link for the documentation.
The below is the example from the documentation, yielding the following donut chart without counts and percentages:
mtcars %>%
head() %>%
dplyr::mutate(model = row.names(.)) %>%
e_charts(model) %>%
e_pie(carb, radius = c("50%", "70%")) %>%
e_title("Donut chart")
What I am looking for is something achieved like this from 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)
Upvotes: 2
Views: 5391
Reputation: 3671
You can define the labels with e_labels
and align the texts with e_title
and 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")
In the documentation the formatters {c} and {d} are listed as
{c}: the value of a data item.
{d}: the percent.
Upvotes: 4