如何向圆环图添加额外的数据标签
How to add additional data label to donut chart
我需要帮助将百分比数据标签添加到我在下面创建的圆环图中。
library(ggpubr)
df <- data.frame(
group = c("Male", "Female"),
value = c(38,62))
head(df)
ggdonutchart(df, "value", label = "group")
ggdonutchart(df, "value", label = "group",
color = "white",fill = "group",
palette = c("hotpink", "lightblue2") )```
ggdonutchart
生成的对象是一个ggplot对象,所以你可以添加一个geom_text
计算百分比。
library(ggpubr)
ggdonutchart(df, "value", label = "group",
color = "white",fill = "group",
palette = c("hotpink", "lightblue2") ) +
geom_text(aes(label = scales::percent(value/sum(value))),
position = position_stack(vjust = 0.5))
我需要帮助将百分比数据标签添加到我在下面创建的圆环图中。
library(ggpubr)
df <- data.frame(
group = c("Male", "Female"),
value = c(38,62))
head(df)
ggdonutchart(df, "value", label = "group")
ggdonutchart(df, "value", label = "group",
color = "white",fill = "group",
palette = c("hotpink", "lightblue2") )```
ggdonutchart
生成的对象是一个ggplot对象,所以你可以添加一个geom_text
计算百分比。
library(ggpubr)
ggdonutchart(df, "value", label = "group",
color = "white",fill = "group",
palette = c("hotpink", "lightblue2") ) +
geom_text(aes(label = scales::percent(value/sum(value))),
position = position_stack(vjust = 0.5))