我正在制作一些漂亮的情节,我可以在需要时复制粘贴(这就是我包含这么多选项的原因)。所以我有这个情节:
library(tidyverse)
mtcars %>%
group_by(cyl) %>%
summarise(n=n()) %>%
ungroup() %>%
mutate(cars = "cars") %>%
ggplot(aes(x = as.factor(cars), y = n, fill=as.factor(cyl))) +
geom_bar(stat="identity", width = .3) +
geom_text(aes(label = paste0(round(n, digits = 0), "stk.")),
position = position_stack(vjust = 0.5)) +
labs(title = "Number of cars with cylinders in the data set",
subtitle= "If needed",
caption= "Fodnote",
x= "", y="Antal",
fill="# of cylinders") +
theme(#legend.position="none",
plot.caption = element_text(hjust = 0))
我如何重新排序堆栈,例如蓝色在底部,然后是红色堆栈和绿色堆栈在顶部。谢谢。我认为解决方案涉及forcats
...