Dear R helpers, 

I have a problem with exporting a chart (to any format). The graphic device 
becomes inactive and I get the 'Error: invalid graphics state' error message. I 
searched the help, web and FAQ but couldn't find the solution.

This is my code:
I chart a histogram for differences in R2 by sample size (an extract from the 
data is below). Altogether I have n=2500 observations (n=500 per sample size)

Size; Delta_R2
60; 0.0073842 
60; 0.0007156 
...
70; 0.0049717
70; 0.0121892 
...
150; 0.0139615 
150; 0.0088114
...
250; 0.0027976
250; 0.0109080 
...
450; 0.0050917
450; 0.0088114
...

The histogram works ok and I can save  or copy to pdf/jpeg/png etc  with no 
problems

library(lattice)
plot.new()
histogram(~Delta_R2|as.factor(Size), type="percent", col="red", xlab="Delta OLS 
- SV R squared", main="R Squared Deviations")  

Once I put the legends (5 text boxes) on the chart and I try to save or copy it 
as pdf / jpeg/png etc I get the above mentioned error message.

This is the code for adding the legends:


*The locations of the legends for each chart
leg_loc=matrix(c( -0.1, 0.26,  0.62, -0.1, 0.26, 0.4, 0.4, 0.4, 1, 1),ncol=2, 
nrow=5, byrow=FALSE)

*Calculate the statistics for each sample size to display on the legends

for (i in 1:5) {
nR=(i-1)*500+1
nR2=nR+499 
z=data[nR:nR2,13]

m<-mean(z)
std<-sqrt(var(z))
iqr=IQR(z)
median=median(z)

*Adding to the chart

legend(leg_loc[i,1],leg_loc[i,2], legend= paste(
"Mean=",round(m,3),'\n',
"SD=",round(std,3),'\n',
"Median =",round(median,3),'\n',
"IQR=", round(iqr,3)),bty="n")
}
Do you know why it is happening? 
Thank you in advance, 
Lena

Elena Wilson
DBM Consultants Pty Ltd
5-7 Guest Street, Hawthorn, Victoria 3122, Australia
T: (61 3) 9819 1555
www.dbmconsultants.com

Please consider the environment before printing this email.

NOTICE - The information contained in this email may be confidential and/or 
privileged. You should only read, disclose, re-transmit, copy, distribute, act 
in reliance on or commercialise the information if you are authorised to do so. 
If you receive this email communication in error, please notify us immediately 
by email to [email protected], or reply by email direct to the sender and 
then destroy any electronic or paper copy of this message.

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

Reply via email to