R设置多图上图形之间的空间 [英] R setting space between graphs on a multiplot
问题描述
在继上一篇R后
您可以在 http://ubuntuone.com/0Nlb97mOeDhSbFrbFKCeEG
现在我的问题是如何删除/减少图形之间的空白区域。我找到了ggExtra软件包,ggplot和facet的示例,带有plot.margin或panel.margin选项的multiplot,但无法找到如何应用于我的案例。
感谢您的帮助。
编辑:我刚刚注意到情节有不一样的宽度。它需要它们具有相同的宽度,以便它们可以从底部图分享x轴标签。使用使用
xlab(NULL)
而不是 xlab()
会从每幅图底部删除一些空格。
使用 opts(plot.margin = unit(c(0,0,0,0),cm))
从边缘开始。
我认为你通过创建5个单独的图并重新组合它们,分面更容易。
mdatos < - melt(datos [,-1],id.vars =dia)
(p_all <-ggplot(mdatos,aes(dia,value))+
geom_line(color =blue)+
facet_grid(variable〜。,scale =free_y) +
xlab(Day)+
ylab(NULL)
)
绘图面板宽度不一样,因为一些y轴标签有三位数字,有些只有两个。要么改变y轴的格式,要么使用我的建议。
Following a previous R post Specifying ggplot2 panel width, I have been able to produce this plot:
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.
这篇关于R设置多图上图形之间的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!