问题
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