Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to control the whole margin of a graph(including plot area and title/footnote) in R?
    primarykey
    data
    text
    <p>I am using both the lattice and ggplots package to create scatterplot in R. when using lattice package, I can contrl the whole graph size (including plot area and title/footnote) with below codes:</p> <pre><code>xyplot( test2 ~ test1, data = in.data, groups = SEX, #title main = textGrob(c("This is the title", "\nThis is the sub-title"), x = unit(c(left.margin,left.margin), "inches"), just = "left", gp = gpar(fontsize = c(title.font, title.font), lineheight=1.5)), #footnote sub = textGrob(paste(footnote1,Sys.time(),sep="\n"), x = unit(c(left.margin), "inches"), y = unit(c(bottom.margin), "inches"), just = c("left", "bottom"), gp = gpar(fontsize = footer.font, lineheight=0.9)) # Figure margins lattice.options = list(layout.widths = leftright.margin, layout.heights = topbottome.margin) ) </code></pre> <p>You can see that the lattice.options can control the whole figure size including title and footnote. while with ggplot2, I create a plot use qplot(...) then control plot margin with:</p> <pre><code>theme(plot.margin=unit(x=c(top.margin,right.margin,bottom.margin,left.margin), units="inches")) </code></pre> <p>then add title and footnote with arrangeGrob. </p> <pre><code> g &lt;- arrangeGrob(myplot, main=textGrob(c(title1, title2), x = unit(c(left.margin,left.margin), "inches"), y = unit(c(-top.margin,-top.margin), "inches"), just = "left", gp = gpar(fontsize = c(title.font, title.font), fontface=c("plain","plain"), lineheight = 1.5)), sub = textGrob(paste(footnote1,Sys.time(),sep="\n"), x = unit(c(left.margin), "inches"), y = unit(c(bottom.margin), "inches"), just = c("left", "bottom"), gp = gpar(fontsize = footer.font,lineheight=0.9))) g </code></pre> <p>In this way, the plot.margin only control the plot area, not control title and footnote. So how should I do to control the both plot area and title area in ggplot2 (just like lattice package)? If the answer is not, in this case I will prefer lattice pakcage.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload