嗨,我想創建一個餅圖,在餅圖中有總頻率,但在外面我想添加標簽?
例如:
temp = structure(list(Var1 = c("diet", "water", "pepsi", "coke", "7_up",
"sprite", "none"), Freq = c(351L, 212L, 71L, 444L, 524L, 193L,
53L), per = c(0.189935064935065, 0.114718614718615, 0.0384199134199134,
0.24025974025974, 0.283549783549784, 0.104437229437229, 0.0286796536796537
)), row.names = c(1L, 3L, 5L, 7L, 9L, 11L, 13L), class = "data.frame")
在這里我可以創建情節,但標簽都混亂了。
ggplot(data = temp,
aes(x = "", y = per, fill = Var1))
geom_col()
geom_text(aes(label = Freq ),
position = position_stack(vjust = 0.5),
color = "grey20", size = 12, fontface = "bold" )
coord_polar(theta = "y", direction = -1 )
theme_void()
theme(legend.position = "none",
legend.direction = "vertical")
theme ( legend.text =element_text(size=12),
legend.title = element_text(size=12) )
geom_label_repel(
aes(
label = Var1, y=per
), box.padding = 0.25
)
圖表看起來像這樣。

uj5u.com熱心網友回復:
除了放置 x = "",您可以放置x = 1??條形,然后x = 1.5放置標簽或其他一些值。本質上嘗試用條形外的標簽制作條形圖,然后如果你轉向極坐標,你應該得到想要的輸出
ggplot(data = temp,
aes(x = 1, y = per, fill = Var1))
geom_col()
geom_text(aes(label = Freq),
position = position_stack(vjust = 0.5),
color = "grey20", fontface = "bold" )
geom_label(aes(x = 1.5, label = Var1),
position = position_stack(vjust = 0.5))
coord_polar(theta = "y", direction = -1 )
theme_void()
theme(legend.position = "none",
legend.direction = "vertical")
theme (legend.text = element_text(size=12),
legend.title = element_text(size=12) )

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/468204.html
下一篇:并排繪制來自兩個資料集的箱線圖
