drc, ggplot2, and gridExtra

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

drc, ggplot2, and gridExtra

Ed Siefker
I have dose response data I have analyzed with the 'drc' package.
Using plot() works great.  I want to arrange my plots and source
data on a single page.  I think 'gridExtra' is the usual package for
this.

I could use plot() and par(mfrow=...), but then I can't put the source
data table on the page.

gridExtra provides grid.table() which makes nice graphical tables. It
doesn't work with par(mfrow=...), but has the function grid.arrange()
instead.

Unfortunately, grid.arrange() doesn't accept plot(). It does work with
qplot() from 'ggplot2'.  Unfortunately, qplot() doesn't know how to
deal with data of class drc.

I'm at a loss on how to proceed here.  Any thoughts?

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: drc, ggplot2, and gridExtra

Eivind K. Dovik
On Fri, 18 May 2018, Ed Siefker wrote:

> I have dose response data I have analyzed with the 'drc' package.
> Using plot() works great.  I want to arrange my plots and source
> data on a single page.  I think 'gridExtra' is the usual package for
> this.
>
> I could use plot() and par(mfrow=...), but then I can't put the source
> data table on the page.
>
> gridExtra provides grid.table() which makes nice graphical tables. It
> doesn't work with par(mfrow=...), but has the function grid.arrange()
> instead.
>
> Unfortunately, grid.arrange() doesn't accept plot(). It does work with
> qplot() from 'ggplot2'.  Unfortunately, qplot() doesn't know how to
> deal with data of class drc.
>
> I'm at a loss on how to proceed here.  Any thoughts?
>

Hi,

If you grab the plots as grobs, you can arrange them using grid.arrange()

library(gridGraphics)
library(gridExtra)

grab <- function{
  grid.echo()
  grid.grab()
}

x <- rnorm(100, 1, 2)
y <- rnorm(100, 0, 0.5)

plot(x,y)
p <- grab()

a <- rnorm(20, 0, 1)
b <- rnorm(20, 1, 2)

plot(a, b)
q <- grab()

grid.arrange(p, q)


Best,
Eivind K. Dovik
Bergen, NO


> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: drc, ggplot2, and gridExtra

R help mailing list-2
Hi, I was able to get Eivind's code to work by slight modification of
the "grab" function:

grab <- function() {
    grid.echo()
    grid.grab()
}

Best Regards,

W. Michels, Ph.D.


On Fri, May 18, 2018 at 9:56 AM, Eivind K. Dovik <[hidden email]> wrote:

> On Fri, 18 May 2018, Ed Siefker wrote:
>
>> I have dose response data I have analyzed with the 'drc' package.
>> Using plot() works great.  I want to arrange my plots and source
>> data on a single page.  I think 'gridExtra' is the usual package for
>> this.
>>
>> I could use plot() and par(mfrow=...), but then I can't put the source
>> data table on the page.
>>
>> gridExtra provides grid.table() which makes nice graphical tables. It
>> doesn't work with par(mfrow=...), but has the function grid.arrange()
>> instead.
>>
>> Unfortunately, grid.arrange() doesn't accept plot(). It does work with
>> qplot() from 'ggplot2'.  Unfortunately, qplot() doesn't know how to
>> deal with data of class drc.
>>
>> I'm at a loss on how to proceed here.  Any thoughts?
>>
>
> Hi,
>
> If you grab the plots as grobs, you can arrange them using grid.arrange()
>
> library(gridGraphics)
> library(gridExtra)
>
> grab <- function{
>         grid.echo()
>         grid.grab()
> }
>
> x <- rnorm(100, 1, 2)
> y <- rnorm(100, 0, 0.5)
>
> plot(x,y)
> p <- grab()
>
> a <- rnorm(20, 0, 1)
> b <- rnorm(20, 1, 2)
>
> plot(a, b)
> q <- grab()
>
> grid.arrange(p, q)
>
>
> Best,
> Eivind K. Dovik
> Bergen, NO
>
>
>> ______________________________________________
>> [hidden email] 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.
>>
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: [FORGED] Re: drc, ggplot2, and gridExtra

Paul Murrell-2
In reply to this post by Eivind K. Dovik
Hi

You need to be careful - you are grid.echo()ing (and then
grid.grab()ing) on full-size pages and then redrawing in half-height
pages, which is why you lose the x-axis labels in the result from
grid.arrange().

This gives a better result (grid.echo() directly in the half-height
viewports) ...

## grid.newpage()
pushViewport(viewport(y=.5, height=.5, just="bottom"))
grid.echo(function() plot(x, y), newpage=FALSE)
upViewport()
pushViewport(viewport(y=0, height=.5, just="bottom"))
grid.echo(function() plot(a, b), newpage=FALSE)
upViewport()

I have been looking for an example that would demonstrate what an
echoGrob() function would be for and I think your grid.arrange() example
might be what I need - thanks for posting this!

Paul

On 19/05/18 04:56, Eivind K. Dovik wrote:

> On Fri, 18 May 2018, Ed Siefker wrote:
>
>> I have dose response data I have analyzed with the 'drc' package.
>> Using plot() works great.  I want to arrange my plots and source
>> data on a single page.  I think 'gridExtra' is the usual package for
>> this.
>>
>> I could use plot() and par(mfrow=...), but then I can't put the source
>> data table on the page.
>>
>> gridExtra provides grid.table() which makes nice graphical tables. It
>> doesn't work with par(mfrow=...), but has the function grid.arrange()
>> instead.
>>
>> Unfortunately, grid.arrange() doesn't accept plot(). It does work with
>> qplot() from 'ggplot2'.  Unfortunately, qplot() doesn't know how to
>> deal with data of class drc.
>>
>> I'm at a loss on how to proceed here.  Any thoughts?
>>
>
> Hi,
>
> If you grab the plots as grobs, you can arrange them using grid.arrange()
>
> library(gridGraphics)
> library(gridExtra)
>
> grab <- function{
>      grid.echo()
>      grid.grab()
> }
>
> x <- rnorm(100, 1, 2)
> y <- rnorm(100, 0, 0.5)
>
> plot(x,y)
> p <- grab()
>
> a <- rnorm(20, 0, 1)
> b <- rnorm(20, 1, 2)
>
> plot(a, b)
> q <- grab()
>
> grid.arrange(p, q)
>
>
> Best,
> Eivind K. Dovik
> Bergen, NO
>
>
>> ______________________________________________
>> [hidden email] 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.
>>
>
> ______________________________________________
> [hidden email] 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.

--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[hidden email]
http://www.stat.auckland.ac.nz/~paul/

______________________________________________
[hidden email] 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.