I'm trying to align multiple plots in R, using ggplot2, so that the x axes line up vertically. However, as you can see, since the legends are different sizes, each 'x' axis is coming out a different width:
The code that I'm using right now is shown below. I'm happy to use any technique that works, not necessarily the approach that I'm using now.
th = theme(legend.key.width = unit(5, "cm"))
plots <- function() {
ss <<- read_csv("support.csv")
ww <<- read_csv("weight.csv")
tt <<- read_csv("totals.csv")
p1 <<- ggplot(data=ss, mapping=aes(t, support, colour=id)) + geom_line() + th
p2 <<- ggplot(data=ww, mapping=aes(t, weight, colour=suppid)) + geom_line() + th
p3 <<- ggplot(data=tt, mapping=aes(t, y, colour=total)) + geom_line() + th
multiplot(p1, p2, p3, cols=1)
}
where multiplot
is copied from cookbook-r.com. As you can see, my attempt to set the width of the legends did not work. I do need to see the legends so that I can tell which line is which (or at least make educated guesses about the middle graph).