Я делаю многопанельный график, используя пакеты ggplot2
и cowplot
, но мне нужно изменить высоту одного графика. Проще всего это показать на примере
library(ggplot2)
library(cowplot)
p1 <- ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species)) +
geom_point() +
theme(axis.text.x = element_blank(),
axis.title.x = element_blank(),
legend.position = "none")
p2 <- ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species)) +
geom_point() +
theme(axis.text.x = element_blank(),
axis.title.x = element_blank(),
axis.text.y = element_blank(),
axis.title.y = element_blank(),
legend.position = "none")
p3 <- ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species)) +
geom_point() +
theme(axis.text.y = element_blank(),
axis.title.y = element_blank(),
legend.position = "none")
p4 <- ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species)) +
geom_point() +
theme(legend.position = "none")
p5 <- ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species)) +
geom_point() +
theme(axis.text.y = element_blank(),
axis.title.y = element_blank(),
legend.position = "none")
pL <- ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species)) + geom_point()
l <- get_legend(pL)
# simple grid
plot_grid(p1, p2, p3, p4, p5, l, ncol = 3)
![enter image description here](https://i.stack.imgur.com/9AtFS.png)
Как вы можете видеть, ось y в крайней правой верхней панели была уменьшена по сравнению с две другие панели в той же строке путем включения заголовка оси X.
Итак как установить относительную высоту и ширину этой отдельной панели, чтобы ось Y совпала с осью Y панелей в верхнем ряду?
Невозможно установить отдельные панели, используя аргументы rel_heights =
и rel_widths() =
, и когда я попытался добавить аргументы axis = "tblr"
и align = "hv"
, я получил сообщение об ошибке
Error in `[.unit.list`(sizes[[x]], list_indices[[x]]) :
index out of bounds (unit list subsetting)