2014-05-18 20 views
3

是否有某些原因导致您无法将两个散点图(来自汽车包装)的图形并排放置?使用汽车零件包散点图并排绘图

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

上面的代码产生两个图像,但不是一个图像并排。

回答

1

scatterplot函数会覆盖您的par()配置,因为它会在内部调用layout()函数以显示散点图以及边缘箱形图。

该问题的创建者John Fox已经回答了这个问题。你可以看到his answer at the R-help mailing list。或者,如果你不信任他,你可以只需have a look at the source code并搜索layout。您会发现在所有情况下调用layout()函数的句子if - else if - else if - else