[R] Boxplots over a Scatterplot

fsch fsch at stanford.edu
Wed Jul 7 23:16:47 CEST 2010


Hello- 

I'm new to R, coding and stats. (Oh no.) 
Anyway, I have about 12000 data points in a data.frame (dealing with
dimensions and geological stage information for fossil protists) and have
plotted them in a basic scatter plot. I also added a boxplot to overlay
these points. Each worked fine independently, but when I attempt to
superimpose them with add=true, I get a different scale for the boxplot,
which results in it being shifted back to the left relative to the scatter
plot. How do I force the boxplot to use the scatterplot's scale or something
to that effect? 

My code. I'm not sure how to include the file I'm using as a dataframe:

#imports data

emdata<-read.table(file="#a file in my working directory", sep=",",
header=T)

#specifies a dataframe

foram<-data.frame(emdata)

#calculates actual dimensions in mm

foram$actual_l<-foram$length/foram$magnification 
foram$actual_w<-foram$width/foram$magnification
foram$actual_h<-foram$height/foram$magnification

#takes logs of all dimensions

foram$logl<-log10(foram$actual_l)
foram$logw<-log10(foram$actual_w)
foram$logh<-log10(foram$actual_h)

#Generates scatterplot

plot(foram$stage,
	foram$logl,
	ylab="log max size",
	xlab="stage",
	cex=.1, 
	xaxt="n",
	axes=FALSE
	)


axis(at=-3:1, side=2, pos=0)
	
axis(at=9:84, side=1,  pos=-3)

#adds a boxplot

boxplot(foram$logl~foram$stage, data=foram, 
outline=F, axes=FALSE, add=TRUE, col="gray82", medlwd=1)


-- 
View this message in context: http://r.789695.n4.nabble.com/Boxplots-over-a-Scatterplot-tp2281526p2281526.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list