Hi, fellow R users, I've been asked to make a plot with two datasets each with a different x axis, and it's been suggested one be at the top and the other at the bottom of the graph. I normally use ggplot2, and I know how to plot multiple datasets by simply + a new geom with a different data option, but usually in these case my different datasets have had the same x and y axes. Can I add a new x axis to the top of the plot in ggplot2 or one of the other graphics packages? Thanks, Ben W. [[alternative HTML version deleted]]
On 02/09/2014 09:57 AM, Benjamin Ward (ENV) wrote:> Hi, fellow R users, > > I've been asked to make a plot with two datasets each with a different x axis, and it's been suggested one be at the top and the other at the bottom of the graph. I normally use ggplot2, and I know how to plot multiple datasets by simply + a new geom with a different data option, but usually in these case my different datasets have had the same x and y axes. Can I add a new x axis to the top of the plot in ggplot2 or one of the other graphics packages? >Hi Ben, The basic method would be something like this: plot(1:4,rnorm(4)) par(new=TRUE) plot(c(10,20,30,40),rnorm(4),axes=FALSE) axis(3,at=c(10,20,30,40)) Obviously you would need to do a bit of messing around with titles and axis labels, etc. Jim
On Feb 8, 2014, at 2:57 PM, Benjamin Ward (ENV) wrote:> Hi, fellow R users, > > I've been asked to make a plot with two datasets each with a different x axis, and it's been suggested one be at the top and the other at the bottom of the graph. I normally use ggplot2, and I know how to plot multiple datasets by simply + a new geom with a different data option, but usually in these case my different datasets have had the same x and y axes. Can I add a new x axis to the top of the plot in ggplot2 or one of the other graphics packages?library(ggplot2) library(gridExtra) x <- qplot(mpg, disp, data = mtcars) y <- qplot(hp, wt, data = mtcars) grid.arrange(x,y) -- David Winsemius Alameda, CA, USA