library(tidyverse)
library(scales)
dat <- read.table(text = "A B C
1 23 234 324
2 34 534 12
3 56 324 124
4 34 234 124
5 123 534 654",
sep = "",
header = TRUE) %>%
gather(key = "variable", value = "value") %>%
mutate(ind = as.factor(rep(1:5, 3)))
ggplot(dat, aes(variable, value, fill = ind)) +
geom_bar(position = "fill", stat = "identity") +
scale_y_continuous(labels = scales::percent_format()) +
facet_grid(~variable, space = "free") +
theme(axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank())
我希望space = "free"
中的facet_grid()
参数可以消除下面每个方面的空白。例如,构面“ A”不应显示空格为“ B”和空格为“ C”的空格。
如何在所有三个方面消除此死区?我只希望每个构面显示一列,并且构面中的其他两个空白列不应被伪绘制。