1

I am using the CAR library scatterplot function trying to do something similar to R: Replace X-axis with own values. However the result is badly formatted. Does anyone know how to replace the x axis values when using scatterplot? My code is below

library(car)
dat = data.frame(x=1:10, y=1:10)
scatterplot(y~x, data=dat, xlab="X axis", ylab="Y Axis", xaxt="n")
axis(1, at=seq(1,10,2), labels=letters[1:5])

With the resulting image

Bad Scatter Plot

Community
  • 1
  • 1
JHowIX
  • 1,683
  • 1
  • 20
  • 38
  • `xlim=c(lower:upper)` ? – hd1 May 29 '14 at 21:14
  • WHAT does "result is badly formatted" actually mean? – IRTFM May 29 '14 at 21:15
  • @hd - adding that to axes(..) didn't seem to change anything. You can use pos=1.2 to get rid of the vertical space but I haven't found anything to change to horizontal alignment or spacing – JHowIX May 29 '14 at 21:20
  • @BondedDust - I thought it would be fairly obvious from the picture but the lettered labeling along the x axis does not align with the tick marks in both scale and spacing. If you look at the link you can contrast with a graph I consider to be correctly formatted. – JHowIX May 29 '14 at 21:21
  • I thought you were referring to how the letters were produced. You actually were bothered by the registration of the labels and tick marks. – IRTFM May 29 '14 at 21:26

1 Answers1

3

Reading the car:::scatterplot help page, as it seems is my calling in life, ....

reset.par   if TRUE then plotting parameters are reset to their previous values when scatterplot 
            exits; if FALSE then the mar and mfcol parameters are altered for the current 
            plotting device. Set to FALSE if you want to add graphical elements (such as lines) 
            to the plot.

Set it to FALSE and try again.

png(); scatterplot(y~x, data=dat, xlab="X axis", ylab="Y Axis", xaxt="n", reset.par=FALSE)
 axis(1, at=seq(1,10,2), labels=letters\[1:5\])
dev.off()

enter image description here

IRTFM
  • 258,963
  • 21
  • 364
  • 487