I am not sure if it is really possible what I want but
here my "wish":
I'd like to show two point-plots in 1 row/2 columns.
They both share there y axis (which should be a log
scale with own labels). The two plots don't share
their x axis (one x axis is log and with different extent).
For each plot there are two groups of points and
I want to display for both groups the regression line.
What I've done so far are two different approaches:
1) create each plot separately and then combine them with
grid.arrange
2) create a facett_plot with free scales
both of the approaches do have some advantages but also
some disadvantages:
1) facett-approach: I don't know how to use set some of the free axis
to log scales and use different labels
2) grid.arrange-approach: the single plots are fine, except that I'd like
the x-axis titles in a grey bar above the plot (like in the facett plots).
Furthermore I don't want ticks on the left side of the plot (for the plots in the right column. And I don't know how to set the margins between left and right column to a narrower space.
I don't know if here the ggExtra package can help me or how to get to what I want.
Hopefully you can help me in doing this.
To explain my problem/task/approaches, I attached a working sample
script with the two outcomes so far (plot.facett, plot.grid). I'd like
more or less a mixture of both...
Thank you very much
Johannes
--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
first thank you for that codesnippet so that I can have these
grey rectangles. It works fine with the dev-version of ggplot.
The grid.arrange is part of the gridExtra package and not a function
of ggExtra. Anyway I managed to get ggExtra installed on R 2.14.0
with: install.packages("ggExtra", repos="http://R-Forge.R-project.org")
There are still some problems:
1) I can't use grid.arrange in the dev-mode.
When I try to use the call it says: Error: could not find function "ggplotGrob"
I don't know how I should change between dev-mode to create the plots and
non-dev mode to use grid.arrange. I tried to load the libaries as follows:
library(gridExtra)
library(devtools)
dev_mode(TRUE)
library(ggplot2)
library(reshape2)
(I followed the approach to load dev-mode as recommended here:
https://gist.github.com/1150934)
2) How can I remove the ticks only from the x axis?
In the opts there is only available: axis.ticks = theme_blank()
So that is for all ticks (x and y axis)
3) How can I set the space between the plots in grid.arrange or
is there any other package that is better for this purpose??
Thank you very much.
/Johannes
-------- Original-Nachricht --------
> Datum: Fri, 11 Nov 2011 11:37:13 -0600
> Von: Winston Chang <winsto...@gmail.com>
> An: Johannes Radinger <JRad...@gmx.at>
> Betreff: Re: how to combined plot: facett vs grid arrange
> Hi Johannes -
> > --
> > You received this message because you are subscribed to the ggplot2
> > mailing list.
> > Please provide a reproducible example: http://gist.github.com/270442
> >
> > To post: email ggp...@googlegroups.com
> > To unsubscribe: email ggplot2+u...@googlegroups.com
> > More options: http://groups.google.com/group/ggplot2
> >
--
I tried to further improve my code and got a least a little bit further:
I managed now to get the text in the grey boxes working and arrange the
plots with grid.layout and pushviewport.
Here is what I did so far:
#creating sample data and dataframe
pred.x1 <-runif(5, 5.0, 7.5)
pred.x2 <- runif(5,0.1,0.9)
pred.x3 <- runif(5,0,1000)
resp.y1 <- runif(5,1,10)
resp.y2 <- runif(5,30,50)
df1 <- data.frame(pred.x1,pred.x2,pred.x3,resp.y1,resp.y2)
########## grid arrange approach ###############
#reshape dataframe for this approach
df3 <-reshape2:::melt.data.frame(df1,id=c("pred.x1", "pred.x2", "pred.x3"),variable.name="resp.name",value.name="resp.value")
# Increase y range by a constant (visually) amount
yrange <- c(1,70)
# This function finds the middle point in a log scale
logmiddle <- function(x) { exp(mean(log(range(x)))) }
# the background rectangle
labelrect <- annotate("rect", xmin=.01, xmax=10000, ymin=52, ymax=90, fill="grey80")
#create single plots
#create single plots
plot.grid1 <- ggplot(df3, aes(x=pred.x1,y=resp.value,colour=resp.name))+
geom_point()+
scale_x_log10(limits=range(df3$pred.x1))+
labelrect +
annotate("text", logmiddle(df3$pred.x1), 65, label="pred.x1", size=4) +
scale_y_log10("Response", limits=yrange, breaks=c(1,5,10,20,50),labels=c(1,5,10,20,50))+
opts(legend.position = "none",
axis.title.x = theme_blank(),
axis.title.y = theme_blank(),
plot.margin = unit(c(0, 0, 0, 0), "cm")
)
plot.grid2 <- ggplot(df3, aes(x=pred.x2,y=resp.value,colour=resp.name))+
geom_point()+
scale_x_log10(limits=range(df3$pred.x2))+
labelrect +
annotate("text", logmiddle(df3$pred.x2), 65, label="pred.x2", size=4) +
scale_y_log10("Response", limits=yrange, breaks=c(1,5,10,20,50),labels=c(1,5,10,20,50))+
opts(legend.position = "none",
axis.title.x = theme_blank(),
axis.title.y = theme_blank(),
axis.text.y = theme_blank(),
plot.margin = unit(c(0, 0, 0, 0), "cm")
)
plot.grid3 <- ggplot(df3, aes(x=pred.x3,y=resp.value,colour=resp.name))+
geom_point()+
scale_x_log10(limits=range(df3$pred.x3))+
labelrect +
annotate("text", logmiddle(df3$pred.x3), 65, label="pred.x3", size=4) +
scale_y_log10("Response", limits=yrange, breaks=c(1,5,10,20,50),labels=c(1,5,10,20,50))+
opts(legend.position = "none",
axis.title.x = theme_blank(),
axis.title.y = theme_blank(),
plot.margin = unit(c(0, 0, 0, 0), "cm")
)
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow=2, ncol=2,
widths = unit(c(7.5,7), "cm"),
heights = unit(rep(5, 2), "cm"))))
print(plot.grid1, vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
print(plot.grid2, vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
print(plot.grid3, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
Just some comments and questions to that:
1) I removed the y-axis text on the right side column plots with opts
2) I set the plot margins to 0 for each plot
3) I had to set the grid.layout column widths manually as on one side
the axis text is removed. I didn't find any other way so that the box
of the left and the right side are exactly the same size.
4) I still don't know how to remove the y axis ticks for plot.grid2
5) I set the text size in the annotation manually to size=4. What is the size of the axis text? Is there any way to use a relative text size?
6) How can I sent the grid.layout - output to a eps/pdf?
And of course I am still interested in the other questions I asked before:
1) How to use log scale for basis e instead of log10?
2) How can I use "scale_shape_manual(value=c(21,16))" in
ggplot dev-mode
Thank you
Johannes
--
Ihr GMX Postfach immer dabei: die kostenlose GMX Mail App für Android.
Komfortabel, sicher und schnell: www.gmx.de/android
2) How can I remove the ticks only from the x axis?
In the opts there is only available: axis.ticks = theme_blank()
So that is for all ticks (x and y axis)