library(dplyr)
library(ggplot2)
library(ggmap) # 為了引用主題theme_nothing,用來消除原始ggplot繪圖自帶的一切標簽
df <- data.frame(value = c(52, 239, 9),
Group = c("Positive", "Negative", "Neutral")) %>%
# factor levels need to be the opposite order of the cumulative sum of the values
mutate(Group = factor(Group, levels = c("Neutral", "Negative", "Positive")),
cumulative = cumsum(value),
midpoint = cumulative - value / 2,
label = paste0(Group, " ", round(value / sum(value) * 100, 1), "%"))
ggplot(df, aes(x = 1, weight = value, fill = Group)) +
geom_bar(width = 1, position = "stack") +
coord_polar(theta = "y") ## 以y軸建立極坐標
+
geom_text(aes(x = 1.3, y = midpoint, label = label)) ## 加上百分比標簽的位置和數(shù)值
+
theme_nothing()








暫無數(shù)據(jù)