[R] split.screen to draw graphs - ggplot2 and lattice (can't slip in 4 cells)

Jim Lemon drjimlemon at gmail.com
Mon Sep 7 12:23:48 CEST 2015


Hi Rosa,
I think all you need is the split.screen commands but this will show you
where each screen number is located:

split.screen(figs=matrix(c(0,0.8,0,1,0.8,1,0,1),ncol=4,byrow=TRUE))
split.screen(figs=matrix(c(0,0.5,0.5,1,0.5,1,0.5,1,0,0.5,0,0.5,0.5,1,0,0.5),
 ncol=4,byrow=TRUE),screen=1)
screen(3)
plot(0:1,0:1,type="n",xlab="",ylab="",axes=FALSE)
box()
text(0.5,0.5,3)
screen(4)
plot(0:1,0:1,type="n",xlab="",ylab="",axes=FALSE)
box()
text(0.5,0.5,4)
screen(5)
plot(0:1,0:1,type="n",xlab="",ylab="",axes=FALSE)
box()
text(0.5,0.5,5)
screen(6)
plot(0:1,0:1,type="n",xlab="",ylab="",axes=FALSE)
box()
text(0.5,0.5,6)
screen(2)
plot(0:1,0:1,type="n",xlab="",ylab="",axes=FALSE)
box()
text(0.5,0.5,2)
close.screen(all=TRUE)

I used width=10,height=6 in the device call.

Jim

On Mon, Sep 7, 2015 at 12:06 AM, Rosa Oliveira <rosita21 at gmail.com> wrote:

> Dear all,
>
>
>
> I need your urgent help J
>
>
>
> I’m naïve, and I’m pretty sure my doubt is very simple to solve, but I’m
> not getting it.
>
>
>
> I used the following code to produce my research graphs, nonetheless, is
> this problem, I do not have 6 graphs (1 – 6),
>
>
>
> #   3   4   5
>
> #                2
>
> #   6   7   8
>
>
>
>
>
> but only 4,instead.  So, I need to reformulate the code, just to
>
>
>
> #   3   4
>
> #                2
>
> #   6   7
>
>
>
> Can you please help me reformulating?
>
> I suppose I have to change something in the split.screen code, because
> nowadays, my “third” column is blank J
>
>
>
>
>
> I attach the code:
>
>
>
> library(ggplot2)
>
> library(reshape)
>
> library(lattice)
>
>
>
> mean.alpha1<-read.csv("graphs_mean_alpha1.csv")
>
> mean.alpha2<-read.csv("graphs_mean_alpha2.csv")
>
> quartz(width=10,height=5)
>
> split.screen(figs=matrix(c(0,0.4,0.5,1,
>
>                            0.4,0.7,0.5,1,
>
>                            0.7,1,0.5,1,
>
>                            0,0.4,0,0.5,
>
>                            0.4,0.7,0,0.5,
>
>                            0.7,1,0,0.5),nrow=6,byrow=TRUE),
>
>              screen=1)
>
>
>
>
>
>
>
> screen(3)
>
> par(mar=c(0,3.5,3,0))
>
> # now the second set
>
> n250<-mean.alpha1$nsample==250
>
> matplot(x=mean.alpha1$lambda[n250],y=mean.alpha1[n250,3:5],
>
>         type="l",pch=1:3,col=c(4,2,3),xaxt="n",ylim=c(-1.2,
> -0.25),main="nsample=250",ylab="", cex.main=1)
>
> abline(h = -1, col = "gray60")
>
> mtext(expression(paste("mean av. for  ",alpha[1])),side=2,line=2,
> cex.main=1)
>
>
>
>
>
>
>
> screen(4)
>
> par(mar=c(0,0,3,0))
>
> # now the second set
>
> n250<-mean.alpha1$nsample==1000
>
> matplot(x=mean.alpha1$lambda[n1000],y=mean.alpha2[n1000,3:5],
>
>         type="l",pch=1:3,col=c(4,2,3),xaxt="n",yaxt="n",ylim=c(-1.2,
> -0.25),main="nsample=1000", cex.main=1)
>
> abline(h = -1, col = "gray60")
>
>
>
>
>
>
>
> screen(6)
>
> par(mar=c(3,3.5,0,0))
>
> # now the second set
>
> n250<-mean.alpha2$nsample==250
>
> matplot(x=mean.alpha2$lambda[n250],y=mean.alpha2[n250,3:5],
>
>         type="l",pch=1:3,col=c(4,2,3),ylim=c(-.6, -.35),ylab="")
>
> abline(h = -.5, col = "gray60")
>
> mtext(expression(paste(lambda)),side=1,line=2, cex.main=1.5)
>
> mtext(expression(paste("mean av. for  ",alpha[2])),side=2,line=2,
> cex.main=1.5)
>
>
>
>
>
>
>
> screen(7)
>
> par(mar=c(3,0,0,0))
>
> # now the second set
>
> n1000<-mean.alpha2$nsample==1000
>
> matplot(x=mean.alpha2$lambda[n1000],y=mean.alpha2[n1000,3:5],
>
> type="l",pch=1:3,col=c(4,2,3),yaxt="n",ylim=c(-.6, -.35))
>
> abline(h = -.5, col = "gray60")
>
> mtext(expression(paste(lambda)),side=1,line=2, , cex.main=1.5)
>
>
>
>
>
> screen(2)
>
> par(mar=c(0,0,0,0))
>
> # plot an empty plot to get the coordinates
>
> plot(0:1,0:1,type="n",axes=FALSE)
>
> legend(0,0.6,c("OLS", "GLS", "Reg. Cal.", "true coefficient"),bty = "n",
> lty=1:3,col=c(4,2,3,"gray60"),xpd=TRUE)
>
>
>
>
>
> close.screen(all=TRUE)
>
>
>
>
>
> BEST,
>
> RO
>
>
>
>
>
> Atenciosamente,
> Rosa Oliveira
>
> --
>
> ____________________________________________________________________________
>
>
> Rosa Celeste dos Santos Oliveira,
>
> E-mail: rosita21 at gmail.com
> Tlm: +351 939355143
> Linkedin: https://pt.linkedin.com/in/rosacsoliveira
>
> ____________________________________________________________________________
> "Many admire, few know"
> Hippocrates
>
> ______________________________________________
> 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