Re: [R] print multiple plots to jpeg, one lattice and one ggplot2

2013-05-05 Thread Christophe Bouffioux
OK thanks
it works

christophe


2013/5/3 Felipe Carrillo 

> Something like this?
> library(gridExtra)
> grid.arrange(one,two)
>
> Felipe D. Carrillo
> Supervisory Fishery Biologist
> Department of the Interior
> US Fish & Wildlife Service
> California, USA
> http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>
>   *From:* Christophe Bouffioux 
> *To:* "r-help@r-project.org" 
> *Sent:* Friday, May 3, 2013 6:33 AM
> *Subject:* [R] print multiple plots to jpeg, one lattice and one ggplot2
>
> hello everybody,
>
> I want to print two plots in one png file, I tried several options but i
> didn't succeed
> the first plot (bwplot) print to the defined position, but the second
> (ggplot) doesn't
> Any idea?
> Thanks a lot
> Christophe
>
>
> #  Example:
> #-
>
> library(ggplot2)
> library(lattice)
> library(grid)
>
> one <- bwplot(decrease ~ treatment, OrchardSprays, groups = rowpos,
>   panel = "panel.superpose",
>   panel.groups = "panel.linejoin",
>   xlab = "treatment",
>   key = list(lines = Rows(trellis.par.get("superpose.line"),
>   c(1:7, 1)),
>   text = list(lab =
> as.character(unique(OrchardSprays$rowpos))),
>   columns = 4, title = "Row position"))
>
>
> df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),
> y = rnorm(30))
> # Compute sample mean and standard deviation in each group
> library(plyr)
> ds <- ddply(df, .(gp), summarise, mean = mean(y), sd = sd(y))
>
> two <- ggplot(df, aes(x = gp, y = y)) +
> geom_point() +
> geom_point(data = ds, aes(y = mean),
>   colour = 'red', size = 3)
>
>
>
> # 1. not working
> jpeg(file=paste(pathgraph,'/fig03_profiltot','.png',sep=''),width = 600,
> height = 400, units="px", res=100)
> print(one, position=c(0,0,0.5,1), more=TRUE)
> print(two, position=c(0.5,0,1,1), )
> dev.off()
>
>
> # 2 not working
> jpeg(file=paste(pathgraph,'/fig03_profiltot','.png',sep=''),width = 600,
> height = 400, units="px", res=100)
> grid.newpage()
> pushViewport(viewport(layout = grid.layout(1, 2)))
>
>   print(one, vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
> # ça ne fonctionne pas
>   print(two, vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
> dev.off()
>
>
>
> # 3 not working
> jpeg(file=paste(pathgraph,'/fig03_profiltot','.png',sep=''),width = 600,
> height = 400, units="px", res=100)
> par(mfrow=c(1,2))
>   one
>   two
> dev.off()
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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]]

__
R-help@r-project.org mailing list
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.


Re: [R] print multiple plots to jpeg, one lattice and one ggplot2

2013-05-03 Thread Felipe Carrillo
Something like this?
library(gridExtra)
grid.arrange(one,two)

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx



>
>From: Christophe Bouffioux 
>To: "r-help@r-project.org"  
>Sent: Friday, May 3, 2013 6:33 AM
>Subject: [R] print multiple plots to jpeg, one lattice and one ggplot2
>
>
>hello everybody,
>
>I want to print two plots in one png file, I tried several options but i
>didn't succeed
>the first plot (bwplot) print to the defined position, but the second
>(ggplot) doesn't
>Any idea?
>Thanks a lot
>Christophe
>
>
>#  Example:
>#-
>
>library(ggplot2)
>library(lattice)
>library(grid)
>
>one <- bwplot(decrease ~ treatment, OrchardSprays, groups = rowpos,
>      panel = "panel.superpose",
>      panel.groups = "panel.linejoin",
>      xlab = "treatment",
>      key = list(lines = Rows(trellis.par.get("superpose.line"),
>                  c(1:7, 1)),
>                  text = list(lab =
>as.character(unique(OrchardSprays$rowpos))),
>                  columns = 4, title = "Row position"))
>
>
>df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),
>                y = rnorm(30))
># Compute sample mean and standard deviation in each group
>library(plyr)
>ds <- ddply(df, .(gp), summarise, mean = mean(y), sd = sd(y))
>
>two <- ggplot(df, aes(x = gp, y = y)) +
>    geom_point() +
>    geom_point(data = ds, aes(y = mean),
>              colour = 'red', size = 3)
>
>
>
># 1. not working
>jpeg(file=paste(pathgraph,'/fig03_profiltot','.png',sep=''),width = 600,
>height = 400, units="px", res=100)
>    print(one, position=c(0,0,0.5,1), more=TRUE)
>    print(two, position=c(0.5,0,1,1), )
>dev.off()
>
>
># 2 not working
>jpeg(file=paste(pathgraph,'/fig03_profiltot','.png',sep=''),width = 600,
>height = 400, units="px", res=100)
>grid.newpage()
>pushViewport(viewport(layout = grid.layout(1, 2)))
>
>      print(one, vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
># ça ne fonctionne pas
>      print(two, vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
>dev.off()
>
>
>
># 3 not working
>jpeg(file=paste(pathgraph,'/fig03_profiltot','.png',sep=''),width = 600,
>height = 400, units="px", res=100)
>    par(mfrow=c(1,2))
>      one
>      two
>dev.off()
>
>    [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list
>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]]

__
R-help@r-project.org mailing list
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.