[R] HELP IN GRAPHS - slip screen (URGENT)
Jim Lemon
drjimlemon at gmail.com
Mon Sep 21 12:52:15 CEST 2015
Hi Rosa,
I think I understand more or less what you want, but the example below uses
made up data as I do not have access to your files. The following code
should produce a block of eight plots with the y axes on the leftmost plots
only and the x axes on the bottom row only. I think I have what you wanted
for the titles. You can get a gap between the two rows of plots if you add
a 0.5 bottom margin to the top row and a 0.5 top margin to the bottom row.
All you have to do is use your data instead of the made up data. I used a
device with width=12 and height=5.
# do the first split, to get the rightmost screen for the legend
split.screen(figs=matrix(c(0,0.84,0,1,0.84,1,0,1),nrow=2,byrow=TRUE))
# now split the first screen to get your eight screens
# (numbered 3 to 10) for the plots
split.screen(figs=matrix(c(0,0.31,0.5,1,
0.31,0.54,0.5,1,
0.54,0.77,0.5,1,
0.77,1,0.5,1,
0,0.31,0,0.5,
0.31,0.54,0,0.5,
0.54,0.77,0,0.5,
0.77,1,0,0.5),
ncol=4,byrow=TRUE),screen=1)
# now make up some data so that I can try out the plot
lambda<-seq(0.7,0.95,by=0.05)
ols_bias_alpha1_250<-c(0.6,0.5,0.4,0.3,0.2,0.1)
ols_bias_alpha1_1000<-c(0.62,0.53,0.44,0.35,0.26,0.17)
gls_bias_alpha1_250<-c(-0.05,0,0.01,0.02,0,-0.01)
gls_bias_alpha1_1000<-c(0.09,0.08,0.07,0.05,0.04,0.045)
screen(3)
par(mar=c(0,4,3,0))
# plot bias for alpha1 250
matplot(lambda,matrix(c(ols_bias_alpha1_250,gls_bias_alpha1_250),ncol=2),
type="l",col=c(4,2),xaxt="n",ylim=c(-.1, .6),
ylab="", cex.main=1)
abline(h = 0, col = "gray60")
mtext("nsample=250",side=3,line=0.6)
mtext(expression(paste("Bias av. for ",alpha[1])),side=2,line=2,
cex.main=1)
screen(4)
par(mar=c(0,0,3,0))
# plot bias for alpha1 1000
matplot(lambda,matrix(c(ols_bias_alpha1_1000,gls_bias_alpha1_1000),ncol=2),
type="l",col=c(4,2),xaxt="n",yaxt="n",ylim=c(-.1, .6),
ylab="", cex.main=1)
abline(h = 0, col = "gray60")
mtext("nsample=1000",side=3,line=0.6)
# now the centered title
par(xpd=TRUE)
mtext("alpha1",side=3,line=1.7,at=0.69)
par(xpd=FALSE)
# make up more data
ols_bias_alpha2_250<-c(-0.04,-0.05,-0.06,-0.05,-0.04,-0.03)
ols_bias_alpha2_1000<-c(-0.04,-0.05,-0.06,-0.05,-0.04,-0.035)
gls_bias_alpha2_250<-c(0.1,0.08,0.06,0.04,0.03,0.01)
gls_bias_alpha2_1000<-c(0.1,0.08,0.06,0.04,0.03,0.01)
screen(5)
par(mar=c(0,0,3,0))
# plot bias for alpha2 250
matplot(lambda,matrix(c(ols_bias_alpha2_250,gls_bias_alpha2_250),ncol=2),
type="l",col=c(4,2),xaxt="n",yaxt="n",ylim=c(-.1, .6),
ylab="", cex.main=1)
abline(h = 0, col = "gray60")
mtext("nsample=250",side=3,line=0.6)
screen(6)
par(mar=c(0,0,3,0))
# plot bias for alpha2 1000
matplot(lambda,matrix(c(ols_bias_alpha2_1000,gls_bias_alpha2_1000),ncol=2),
type="l",col=c(4,2),xaxt="n",yaxt="n",ylim=c(-.1, .6),
ylab="", cex.main=1)
abline(h = 0, col = "gray60")
mtext("nsample=1000",side=3,line=0.6)
# now the centered title
par(xpd=TRUE)
mtext("alpha2",side=3,line=1.7,at=0.69)
par(xpd=FALSE)
# more data!
ols_se_alpha1_250<-c(0.45,0.46,0.47,0.48,0.49,0.51)
gls_se_alpha1_250<-c(0.7,0.62,0.58,0.56,0.54,0.52)
ols_se_alpha1_1000<-c(0.2,0.21,0.22,0.23,0.24,0.251)
gls_se_alpha1_1000<-c(0.3,0.29,0.28,0.27,0.26,0.252)
screen(7)
par(mar=c(3,4,0,0))
# plot SE for alpha1 250
matplot(lambda,matrix(c(ols_se_alpha1_250,gls_se_alpha1_250),ncol=2),
type="l",col=c(4,2),ylim=c(0,1.1),
ylab="", cex.main=1)
mtext(expression(paste("SE av. for ",alpha[1])),side=2,line=2, cex.main=1)
mtext(expression(paste(lambda)),side=1,line=2, cex.main=1.5)
screen(8)
par(mar=c(3,0,0,0))
# plot SE for alpha1 1000
matplot(lambda,matrix(c(ols_se_alpha1_1000,gls_se_alpha1_1000),ncol=2),
type="l",col=c(4,2),ylim=c(0,1.1),yaxt="n",
ylab="", cex.main=1)
mtext(expression(paste(lambda)),side=1,line=2, cex.main=1.5)
# even more data!
ols_se_alpha2_250<-c(0.12,0.13,0.14,0.16,0.18,0.2)
gls_se_alpha2_250<-c(0.3,0.26,0.24,0.22,0.21,0.2)
ols_se_alpha2_1000<-c(0.1,0.11,0.12,0.13,0.14,0.15)
gls_se_alpha2_1000<-c(0.2,0.19,0.18,0.17,0.16,0.15)
screen(9)
par(mar=c(3,0,0,0))
# plot SE for alpha1 250
matplot(lambda,matrix(c(ols_se_alpha2_250,gls_se_alpha2_250),ncol=2),
type="l",col=c(4,2),ylim=c(0,1.1),
yaxt="n",ylab="", cex.main=1)
mtext(expression(paste(lambda)),side=1,line=2, cex.main=1.5)
screen(10)
par(mar=c(3,0,0,0))
# plot SE for alpha1 1000
matplot(lambda,matrix(c(ols_se_alpha2_1000,gls_se_alpha2_1000),ncol=2),
type="l",col=c(4,2),ylim=c(0,1.1),yaxt="n",
ylab="", cex.main=1)
mtext(expression(paste(lambda)),side=1,line=2, cex.main=1.5)
# finally the legend
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.", "0"),bty = "n",
lty=1:3,col=c(4,2,3,"gray60"),xpd=TRUE)
close.screen(all=TRUE)
Jim
On Mon, Sep 21, 2015 at 2:14 AM, Rosa Oliveira <rosita21 at gmail.com> wrote:
> Dear Jim,
>
>
> I’ve tried till today, but I could not solve the problems.
>
> 1. despite the scales are the same (equal: lambda ={0.70, 0.75, 0.80,
> 0.85, 0.90, 0.95, 0.98}), the "matrix" is not equal. If you see, for n =
> 250 the column is narrower than for n = 1000, and "lambda" has the same
> values.
>
> 2. the first 2 columns relate to alpha 1 and the second two columns
> alpha2. Is it possible to place a title above nsample that concerns the
> first 2 columns and other over the last 2?
>
> something like:
>
> *alpha1*
> *alpha2*
> nsample=250 nsample=1000 nsample=250
> nsample=1000
>
>
> 3. Notice that have 4 separate drawings and must place the 4 "groups"
> together.
> ...
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list