Change Axis Label - R scatterplot

跟風遠走 提交于 2019-12-08 08:13:06

问题


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


回答1:


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()



来源:https://stackoverflow.com/questions/23942855/change-axis-label-r-scatterplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!