2
值標籤我試圖用GGPLOT2配合我的餅圖標籤:GGPLOT2 - 餅圖 - 按相反的順序
代碼:
values=c(59,4,4,11,26)
labels=c("catA", "catB","catC","catD","catE")
pos = cumsum(values)- values/2
graph <- data.frame(values, labels,pos)
categoriesName="Access"
percent_str <- paste(round(graph$values/sum(graph$values) * 100,1), "%", sep="")
values <- data.frame(val = graph$values, Type = graph$labels, percent=percent_str, pos = graph$pos)
pie <- ggplot(values, aes(x = "", y = val, fill = Type)) +
geom_bar(width = 1,stat="identity") +
geom_text(aes(x= "", y=pos, label = val), size=3)
pie + coord_polar(theta = "y")
我讀到這些主題,但沒有任何成功:
- ggplot, facet, piechart: placing text in the middle of pie chart slices
- R + ggplot2 => add labels on facet pie chart