I am making a multi-panel plot using ggplot2
and cowplot
packages, but I need to change the height of a single plot. It is easiest shown with an example
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)
As you can see the y axis in the far right top panel has been shrunk in comparison with the two other panels in the same row by the inclusion of the x-axis title.
So how do I set the relative height and width of this single panel, so that the y-axis aligns with the y-axis of the panels in the top row?
You cannot set individual panels using rel_heights =
and rel_widths() =
arguments, and when I tried to add axis = "tblr"
and align = "hv"
arguments I got the error message
Error in `[.unit.list`(sizes[[x]], list_indices[[x]]) :
index out of bounds (unit list subsetting)