Fox, John
2020-May-03 03:47 UTC
[R] possible issue with scatterplot function in car package
Dear Yousri, Yes, this is clearly a bug, and almost surely a long-standing one. We'll fix it in the next release of the car package. BTW, stringsAsFactors defaults to FALSE in R 4.0.0 (and you don't use the ch variable in the example). Also, although it has no bearing on the bug, I'd generally prefer scatterplot(y ~ x, data=aa, smooth=FALSE, grid=FALSE, frame=FALSE, regLine=FALSE, xlim=c(0, 8)) Thank you for the bug report, John ----------------------------- John Fox, Professor Emeritus McMaster University Hamilton, Ontario, Canada Web: http::/socserv.mcmaster.ca/jfox> On May 2, 2020, at 7:30 PM, Yousri Fanous <yousri.fanous at gmail.com> wrote: > > library (car) > > aa <- data.frame(x=c(2, 5, 6, 7, 8), > + y=c(5, 10, 9, 12, 11), > + ch=c("N", "Q", "R", "S", "T"), > + stringsAsFactors=FALSE) > > scatterplot(aa$x,aa$y,smooth = FALSE, grid = FALSE, frame = FALSE,regLine=F) > > Both x and y boxplots are correct > and in particular the median of the x box is at 6 which is confirmed > >> median(aa$x) > [1] 6 > > Now I do only one addition to the scatterplot: I add xlim >> scatterplot(aa$x,aa$y,smooth = FALSE, grid = FALSE, frame > FALSE,regLine=F,xlim=c(0,8)) > > This causes the boxplot on x-axis to be in error: > 1) the lower whisker starts now from zero > 2) the median is between 4 and 6 and no longer at 6 as before > >> sessionInfo() > R version 3.6.3 (2020-02-29) > [1] car_3.0-7 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Yousri Fanous
2020-May-03 08:37 UTC
[R] possible issue with scatterplot function in car package
Thank you Professor John for your answer. As you rightly said I am not using the ch in my example report as it has no bearing to the issue. However it is the ch that led me to find the issue. I was trying to label each point with its corresponding aa$ch value. I used this code: scatterplot(aa$x,aa$y,smooth = FALSE, grid = FALSE, frame = FALSE,regLine=F) text(aa$x,aa$y, labels=aa$ch,font=1 ,cex=.9,pos=3) The annotation was correct for 4 points but not for the (2,5) point. I figured it is because it is close to the margin of the plot hence as a quick solution I modified xlim to shift the point away from the margin. This worked for the annotation but eventually led to the issue I described. Thank you so much for your time Yousri Fanous Software Developer IBM CANADA On Sat, May 2, 2020 at 11:47 PM Fox, John <jfox at mcmaster.ca> wrote:> > Dear Yousri, > > Yes, this is clearly a bug, and almost surely a long-standing one. We'll > fix it in the next release of the car package. > > BTW, stringsAsFactors defaults to FALSE in R 4.0.0 (and you don't use the > ch variable in the example). Also, although it has no bearing on the bug, > I'd generally prefer > > scatterplot(y ~ x, data=aa, smooth=FALSE, grid=FALSE, > frame=FALSE, regLine=FALSE, xlim=c(0, 8)) > > Thank you for the bug report, > John > > ----------------------------- > John Fox, Professor Emeritus > McMaster University > Hamilton, Ontario, Canada > Web: http::/socserv.mcmaster.ca/jfox > > > On May 2, 2020, at 7:30 PM, Yousri Fanous <yousri.fanous at gmail.com> > wrote: > > > > library (car) > > > > aa <- data.frame(x=c(2, 5, 6, 7, 8), > > + y=c(5, 10, 9, 12, 11), > > + ch=c("N", "Q", "R", "S", "T"), > > + stringsAsFactors=FALSE) > > > > scatterplot(aa$x,aa$y,smooth = FALSE, grid = FALSE, frame > FALSE,regLine=F) > > > > Both x and y boxplots are correct > > and in particular the median of the x box is at 6 which is confirmed > > > >> median(aa$x) > > [1] 6 > > > > Now I do only one addition to the scatterplot: I add xlim > >> scatterplot(aa$x,aa$y,smooth = FALSE, grid = FALSE, frame > > FALSE,regLine=F,xlim=c(0,8)) > > > > This causes the boxplot on x-axis to be in error: > > 1) the lower whisker starts now from zero > > 2) the median is between 4 and 6 and no longer at 6 as before > > > >> sessionInfo() > > R version 3.6.3 (2020-02-29) > > [1] car_3.0-7 > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. > >[[alternative HTML version deleted]]
Fox, John
2020-May-04 02:54 UTC
[R] possible issue with scatterplot function in car package
Dear Yousri, The problem with scatterplot() is now fixed in the development version 3.0-8 of the car package on R-Forge, which eventually will be submitted to CRAN. Until then, you can install the package via install.packages("car", repos="http://R-Forge.R-project.org") Thanks again for the bug report, John> On May 3, 2020, at 4:37 AM, Yousri Fanous <yousri.fanous at gmail.com> wrote: > > Thank you Professor John for your answer. > > As you rightly said I am not using the ch in my example report as it has no bearing to the issue. > However it is the ch that led me to find the issue. > I was trying to label each point with its corresponding aa$ch value. > I used this code: > > scatterplot(aa$x,aa$y,smooth = FALSE, grid = FALSE, frame = FALSE,regLine=F) > text(aa$x,aa$y, labels=aa$ch,font=1 ,cex=.9,pos=3) > > The annotation was correct for 4 points but not for the (2,5) point. > I figured it is because it is close to the margin of the plot hence as a quick solution I modified xlim to shift the point away from the margin. > This worked for the annotation but eventually led to the issue I described. > > Thank you so much for your time > > Yousri Fanous > > Software Developer > IBM CANADA > > On Sat, May 2, 2020 at 11:47 PM Fox, John <jfox at mcmaster.ca> wrote: > > Dear Yousri, > > Yes, this is clearly a bug, and almost surely a long-standing one. We'll fix it in the next release of the car package. > > BTW, stringsAsFactors defaults to FALSE in R 4.0.0 (and you don't use the ch variable in the example). Also, although it has no bearing on the bug, I'd generally prefer > > scatterplot(y ~ x, data=aa, smooth=FALSE, grid=FALSE, > frame=FALSE, regLine=FALSE, xlim=c(0, 8)) > > Thank you for the bug report, > John > > ----------------------------- > John Fox, Professor Emeritus > McMaster University > Hamilton, Ontario, Canada > Web: http::/socserv.mcmaster.ca/jfox > > > On May 2, 2020, at 7:30 PM, Yousri Fanous <yousri.fanous at gmail.com> wrote: > > > > library (car) > > > > aa <- data.frame(x=c(2, 5, 6, 7, 8), > > + y=c(5, 10, 9, 12, 11), > > + ch=c("N", "Q", "R", "S", "T"), > > + stringsAsFactors=FALSE) > > > > scatterplot(aa$x,aa$y,smooth = FALSE, grid = FALSE, frame = FALSE,regLine=F) > > > > Both x and y boxplots are correct > > and in particular the median of the x box is at 6 which is confirmed > > > >> median(aa$x) > > [1] 6 > > > > Now I do only one addition to the scatterplot: I add xlim > >> scatterplot(aa$x,aa$y,smooth = FALSE, grid = FALSE, frame > > FALSE,regLine=F,xlim=c(0,8)) > > > > This causes the boxplot on x-axis to be in error: > > 1) the lower whisker starts now from zero > > 2) the median is between 4 and 6 and no longer at 6 as before > > > >> sessionInfo() > > R version 3.6.3 (2020-02-29) > > [1] car_3.0-7 > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. >