Following a previous R post Specifying ggplot2 panel width, I have been able to produce this plot:
with this code.
You can find the output of dput(datos) at http://ubuntuone.com/0Nlb97mOeDhSbFrbFKCeEG
Now my question is how can I remove/reduce the white space between the graphs. I have found examples with ggExtra package, ggplot and facet, multiplots with options as plot.margin or panel.margin but couldn't find how to apply to my case.
Thanks for your help.
EDIT: I have just noticed that plots have not the same width. It is needed they have the same width so they can share x axis labels from bottom plot.
Using xlab(NULL)
instead of xlab(" ")
will remove some space off the bottom of each plot.
Using opts(plot.margin = unit(c(0,0,0,0), "cm"))
will remove a little space from the edges.
I think that your have overcomplicated things by creating 5 separate graphs and recombining them. Faceting is much easier.
mdatos <- melt(datos[, -1], id.vars = "dia")
(p_all <- ggplot(mdatos, aes(dia, value)) +
geom_line(colour = "blue") +
facet_grid(variable ~ ., scale = "free_y") +
xlab("Day") +
ylab(NULL)
)
The plot panels aren't the same width because some y axis labels have three digit numbers, and some only two. Either change the formatting of the y axis, or use my facetting suggestion.
You can layout and control the margins of several subplots with par
and layout
. For example:
par (fig=c(0,1,0,1), # Figure region in the device display region (x1,x2,y1,y2)
omi=c(0,0,0.3,0), # global margins in inches (bottom, left, top, right)
mai=c(0.1,0.1,0.3,0.1)) # subplot margins in inches (bottom, left, top, right)
layout(matrix(1:4, 2, 2, byrow = TRUE))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With