我想从第一个图中再删一列而不改变两个图中条形的宽度或对齐方式。非常感谢任何帮助。
theme_min <-
theme(
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
panel.background = element_blank(),
panel.border = element_blank(),
axis.line = element_line(colour = "black")
)
# display 2 of 4 columns
mtcars %>%
mutate(
am = factor(am, labels = c("auto", "manual")),
vs = factor(vs, labels = c("V", "S"))
) %>%
filter(
am == "auto"
) %>%
ggplot(aes(x = am, y = mpg, fill = vs)) +
geom_col(position = position_dodge()) +
scale_y_continuous(limits = c(0,35)) +
theme_min +
scale_x_discrete(drop = FALSE)
# display 1 of 4 columns
mtcars %>%
mutate(
am = factor(am, labels = c("auto", "manual")),
vs = factor(vs, labels = c("V", "S"))
) %>%
filter(
am == "auto",
vs == "V"
) %>%
ggplot(aes(x = am, y = mpg, fill = vs)) +
geom_col(position = position_dodge()) +
scale_y_continuous(limits = c(0,35)) +
theme_min +
scale_x_discrete(drop = FALSE) +
scale_fill_discrete(drop = FALSE)