Side by side plots using scatterplot from car package

天大地大妈咪最大 提交于 2019-12-12 15:25:28

问题


Is there some reason you cannot lay two scatterplot (from car package) figures side by side?

library(car)

str(UN)

par(mfrow=c(1,2))
scatterplot(infant.mortality~gdp,data=UN,
            xlab="GDP per capita",
            ylab="Infant Morality Rate (per 1000 births)",
            main="(a)",
            boxplot=FALSE)
scatterplot(infant.mortality~gdp,data=UN,
            xlab="GDP per capita",
            ylab="Infant Morality Rate (per 1000 births)",
            main="(b)",
            log='xy',
            boxplot=FALSE,id.n=4)
par(mfrow=c(1,1))

The above code produces both images, but not as one image side by side.


回答1:


The scatterplot function overrides your par() configuration, as it calls internally the layout() function to display the scatterplot along with the marginal boxplots.

This question was already answered by John Fox, the creator of that function. You can see his answer at the R-help mailing list.

Or, if you do not trust him, you can just have a look at the source code and search for layout. You will find the if - else if - else if - else sentence in which the layout() function is called in all cases.



来源:https://stackoverflow.com/questions/23725871/side-by-side-plots-using-scatterplot-from-car-package

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