【发布时间】:2022-01-21 15:23:43
【问题描述】:
我的标签与堆叠条形图的每一侧大致对齐。问题是它们看起来像一团糟,因为它们在栏的两边都不是左右对齐的。我该如何解决这个问题,让他们看起来很专业?
df3 <- data.frame(
Label = c("Dasher", "Dancer", "Comet", "Cupid", "Prancer", "Blitzen", "Rudolph"),
Amount = c(650.01, 601.01, 340.05, 330.20, 260.01, 250.80, 10.10)
)
# Sort order
level_order <- df3 %>%
arrange(desc(Amount))
ggplot(level_order, aes(fill=fct_inorder(Label), y=Amount, x="")) +
geom_bar(position="stack", stat="identity", width = 0.55) +
scale_fill_brewer(palette = "Blues", direction = -1) +
theme_void() +
geom_text(aes(label = paste0("$", Amount)),
position = position_stack(vjust = 0.5),
hjust = -3.1,
size = 5) +
geom_text(aes(label = Label),
position = position_stack(vjust = 0.5),
hjust = 5,
size = 5) +
theme(legend.position = "none") +
theme(plot.title = element_text(size = 50, hjust = .5, vjust = 0)) +
ggtitle("Food Costs by Reindeer")
【问题讨论】:
-
你能否把问题说得更清楚些:你想让左手标签左对齐,右手标签右对齐吗?
-
我们从中学到了什么?鲁道夫是真正的交易!
标签: r ggplot2 data-visualization