[R] x axis position and ggplot2

Duncan Mackay dulcalma at bigpond.com
Fri Dec 12 16:57:26 CET 2014


Hi Céline

 

ggplot2 and lattice have different constructs to the base graphics – although they may share some common arguments like xlab, lwd col etc the rest may be totally different. 

 

In the latticeExtra package I think there is a function to make the lattice look like ggplot. I have never used it as I stick to lattice.

 

There may be something at Hadley’s web site for ggplot2 that may  do.

 

The other alternative is to add  the axis labels and the x label with using textGrob from library(grid) to put the axis at the top. It would be a bit fiddly but if you have to …

 

Regards

 

Duncan 

 

 

From: Jouanin Celine [mailto:celine_jouanin at yahoo.fr] 
Sent: Friday, 12 December 2014 19:16
To: Duncan Mackay; R; Jeff Newmiller
Subject: Re: [R] x axis position and ggplot2

 

Hi,

 

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,

 

Céline

  _____  

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


Hi 

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

http://tolstoy.newcastle.edu.au/R/e2/help/07/05/17666.html

library(grid)
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)
  }
  lab.gf
}

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

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
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.






	[[alternative HTML version deleted]]



More information about the R-help mailing list