[R] x axis position and ggplot2

Jouanin Celine celine_jouanin at yahoo.fr
Fri Dec 12 10:15:39 CET 2014

Thank you for your answer, I thought we could used something like the "axis" function ( axis(side=3,...)) in ggplot2. 
I didn't find something like this in ggplot and I'm a bite surprised this doesn't exist. 
Sometimes we need to use lattice, grid -thank you Duncan for your help, or ggplot or other package, depending on what we want to show and the type of plot. Anyway, as I really need to use the ggplot package, I suppose that I'll plot my data without the axis on the top.Have a nice day,

     De : Duncan Mackay <dulcalma at bigpond.com>
 À : R <r-help at r-project.org>; 'Jouanin Celine' <celine_jouanin at yahoo.fr> 
 Envoyé le : Jeudi 11 décembre 2014 2h57
 Objet : RE: [R] x axis position and ggplot2

I do not know ggplot2 well enough to give any advice but as Geff has mention lattice see


myXlabGrob <-
function(...){ ## ...is lab1, lab2, etc

  # you can add arguments to textGrob for more control  in the next line
  labs <- lapply(list(...), textGrob)
  nlabs <- length(labs)

  lab.heights <-
  lapply(labs, function(lab) unit(1, "grobheight", data = list(lab)))

  lab.layout <-
  grid.layout(ncol = nlabs, nrow = 1,
                  heights = do.call(max, lab.heights),
                  widths = unit(1, "null"),
                  respect = TRUE)

  lab.gf <- frameGrob(layout = lab.layout)

  for (i in seq_len(nlabs)){
    lab.gf <- placeGrob(lab.gf, labs[[i]], row = 1, col = i)

xyplot(1:10 ~ 1:10,
        scales = list(x = list(alternating = 2)), # puts scale on the top rather than the bottom
        xlab = "", # removes label at bottom
        xlab.top = myXlabGrob('B')


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 [mailto:r-help-bounces at r-project.org] On Behalf Of Jouanin Celine
Sent: Thursday, 11 December 2014 02:44
To: r-help at r-project.org
Subject: [R] x axis position and ggplot2

Hi all,
Is it possible to change the position of the x axis to have it at the top of the plot when we use the ggplot function ?Thanks for your help,Céline

    [[alternative HTML version deleted]]

R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]

More information about the R-help mailing list