Using:
library(dplyr)
df <- df %>%
mutate(end = 2 * pi * cumsum(Value)/sum(Value),
start = lag(end, default = 0),
middle = 0.5 * (start + end),
hjust = ifelse(middle > pi, 1, 0),
vjust = ifelse(middle < pi/2 | middle > 3 * pi/2, 0, 1))
library(ggforce) # for 'geom_arc_bar'
ggplot(df) +
geom_arc_bar(aes(x0 = 0, y0 = 0, r0 = 0, r = 1,
start = start, end = end, fill = Product)) +
geom_text(aes(x = 1.05 * sin(middle), y = 1.05 * cos(middle), label = Label,
hjust = hjust, vjust = vjust)) +
coord_fixed() +
scale_x_continuous(limits = c(-1.5, 1.5), # Adjust so labels are not cut off
name = "", breaks = NULL, labels = NULL) +
scale_y_continuous(limits = c(-1, 1.1), # Adjust so labels are not cut off
name = "", breaks = NULL, labels = NULL)
gives:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…