Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To display a label in echarts4r as a percentage, you can use the formatter argument in the series function. Here's an example code:

library(echarts4r)

# Create a data frame
df <- data.frame(x = c("A", "B", "C"),
                 y = c(60, 30, 10))

# Generate a pie chart with percentage labels
echarts4r() %>%
  add_pie(df, name = "Label",
          label = list(formatter = "{b}: {d}%")) %>%
  e_theme("dark")

In the formatter argument, we used the {d}% syntax to display the data value as a percentage. We also used the {b} syntax to display the name of the data point. You can customize the formatting based on your needs.