Hi everyone, I have a problem with adding points to scatter plots. The plot is drawn with the scatterplot() function from the car library: scatterplot(data[,2] ~ data[,1], data=data,smooth=F,reg.line=F,xlim=c(0.5,1),ylim=c(0.5,1),ylab="ML",xlab="Freq",cex.lab=1.9,cex.axis=1.8) after that, I draw one line with abline(0,1,col="gray20") which works perfectly fine. now I want to add, say the point (0.6,0.6) to the plot with points(c(0.6),c(0.6)). The point is plotted, but not exactly at the proper coordinates, but at something like (0.55,0.55). When I use the plot() function to make the scatter plots, this problem does not occur, but I want to have those nice box plots next to the X and Y-axes that are drawn by scatterplot().. Anybody has an idea how to get the points at the right place in the plot? cheers, Peter
Additional points to scatter plot show up at wrong place
3 messages · Peter Menzel, Stefan Grosse, Peter Dalgaard
On Fri, 15 May 2009 15:43:33 +0200 Peter Menzel
<pmenzel at googlemail.com> wrote:
PM> scatterplot(data[,2] ~ data[,1], PM> data=data,smooth=F,reg.line=F,xlim=c(0.5,1),ylim=c(0.5,1),ylab="ML",xlab="Freq",cex.lab=1.9,cex.axis=1.8) Side remark: you don't need do data[,2] if you have specified data=data as you did. So var1~var2 would be enough. PM> after that, I draw one line with abline(0,1,col="gray20") which PM> works perfectly fine. abline for me also does not work in the expected way, see below. PM> now I want to add, say the point (0.6,0.6) to the plot with PM> points(c(0.6),c(0.6)). the c() is not necessary points(0.6,0.6) is enough. PM> The point is plotted, but not exactly at the proper coordinates, but PM> at something like (0.55,0.55). That seems to be a bug. The axis seems not to be drawn exactly. to replicate see: library(car) data<-data.frame(x1=rnorm(100),x2=rnorm(100,.25)) scatterplot(x1~x2,data=data,ylab="ML",xlab="Freq") points(0.5,0.5,col="blue") abline(h=0.5,lty=2) # check whether point is at the correct location. abline(v=0.5,lty=2) abline(h=1) # line is not at 1 at the y-axis! So maybe one can contact the package owner? Btw. creating such a plot by yourself is easy, have a look at ?layout ?axis Stefan
Peter Menzel wrote:
Hi everyone, I have a problem with adding points to scatter plots. The plot is drawn with the scatterplot() function from the car library: scatterplot(data[,2] ~ data[,1], data=data,smooth=F,reg.line=F,xlim=c(0.5,1),ylim=c(0.5,1),ylab="ML",xlab="Freq",cex.lab=1.9,cex.axis=1.8) after that, I draw one line with abline(0,1,col="gray20") which works perfectly fine. now I want to add, say the point (0.6,0.6) to the plot with points(c(0.6),c(0.6)). The point is plotted, but not exactly at the proper coordinates, but at something like (0.55,0.55).
scatterplot() is using layout() inter?ally, so you can't expect this to work. I don't think there's a nice way of going back to a previous subregion.
When I use the plot() function to make the scatter plots, this problem does not occur, but I want to have those nice box plots next to the X and Y-axes that are drawn by scatterplot().. Anybody has an idea how to get the points at the right place in the plot? cheers, Peter
______________________________________________ R-help at r-project.org 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.
O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907