我想将勾号和批注文本放在拼图之外,但这样做不正确.
以下是代码:
library(ggplot2)
library(ggrepel)
cars <- data.frame(category = c("civic", "MG", "Suzuki", "Tesla"),
count = c (14810, 6457, 18233, 571),
percentage = c(37,16,46,1))
ggplot(cars, aes(x="", y=count, fill=category)) +
geom_bar(stat="identity", width=1, alpha = 0.5, color = "black") +
coord_polar("y", start=0) +
geom_label_repel(data = cars,
aes(y = count, label = paste0(percentage, "%")),
size = 4.5, nudge_x = 1, show.legend = FALSE) +
labs(fill = "Category") +
scale_color_gradientn(colours = rainbow(4)) +
theme_void() +
theme(legend.position = "right",
text = element_text(family = "serif", colour = "black"))
但我想要的是: