[R] Control the whole margin of a graph(including plot area and title/footnote) in R

Duncan Mackay dulcalma at bigpond.com
Wed Nov 27 07:20:50 CET 2013


Hi

I do not know what in.data is and I am not familiar with ggplot2

and I am not sure what you mean

I think you need to keep things simple and explain what you want and dput a
dataset

Try this

xyplot(test2 ~ test1, data     = in.data,
       groups   = SEX,
       par.settings = list(par.main.text = list(cex = 0.8)),
      main = "This is the title\nThis is the sub-title"
)

also have a look at

?lattice::plot.trellis

If you want to split your graph area into several "panes"

HTH

Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Mina Chen
Sent: Wednesday, 27 November 2013 12:22
To: r-help at r-project.org
Subject: [R] Control the whole margin of a graph(including plot area and
title/footnote) in R

Hi,

I am a novice of R and I have attended the coursea courses for computing for
R analysis.
Recently 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:

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)
)
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:
theme(plot.margin=unit(x=c(top.margin,right.margin,bottom.margin,left.margin
),units="inches"))
then  add title and footnote with arrangeGrob.
 g<-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

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.

I will very appreciate your reply! Thanks!


Best regards,
Mina

	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list