[R] Adding lines to scatterplot odd result when creating multiple plots

markm0705 markm0705 at gmail.com
Mon Nov 7 23:46:22 CET 2011


Dear R helpers

I'm attempting to create a matrix of scatterplots with X-Y mean lines and
regression lines added to each plot in the matrix.  I have managed to create
the first plot I would like using scatterplot but have run into an odd
result when I use par() to set up the page to take multiple plot. 
Specifically, the mean and regression lines appear to plot in the second
plot window, not on top of the scatterplot (when I include the par(mfcol)
command).  

How do I get the scatterplot and added lines to stay together on this plot
and subsequent plots I would like to include in the scatterplot matrix

Data attached

Thanks in advance MarkM

library("car")

par(mfcol=c(1,2))

# Parameters to change

Infile<-"kt3d_Thk1.dat"
X<-"Estimated thickness (mE)"
Y<-"True thickness (mE)"

#load data
#read the data skip then read header

crossval <- read.table(Infile,skip = 9,sep = "")
head<-readLines(Infile,9)

#decode the header lines wanted

head2<-head[3:9]
colnames(crossval)=head2

#Filter out non-estimated

crossval2<-crossval[crossval$Estimate>0,]

# Compute the means

AveEst<-mean(crossval2$Estimate)
AveTru<-mean(crossval2$True)

#Fit the regression line

Fit<-lm(crossval2$True~crossval2$Estimate )

#create plots

scatterplot(True ~ Estimate,
	data=crossval2,
	xlab= X,
	ylab= Y,
	main= "Min 4 Max 8",
	grid=FALSE,
	xlim=c(0,8),
	ylim=c(0,8),
	pch=21,
	cex=1.2,
	smooth=FALSE,
	reg.line=FALSE
)


#Plot mean lines and regression

abline(h=AveTru,col="grey70")
abline(v=AveEst,col="grey70")
abline(0,1,col="red")
abline(lm(crossval2$True~crossval2$Estimate), col="blue", lty=1, lwd=2)

--
View this message in context: http://r.789695.n4.nabble.com/Adding-lines-to-scatterplot-odd-result-when-creating-multiple-plots-tp4014140p4014140.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list