如何在同一窗口中显示两个直方图但在 R 中显示不同的图?

som*_*adi 3 plot r histogram

我想在直方图上展示去除异常值的效果,所以我必须将两个直方图绘制在一起。

boxplot(Costs, Costs1,
    xlab=" Costs    and    Costs after  removig outliers",
    col=topo.colors(2))
Run Code Online (Sandbox Code Playgroud)

所以我试过这个:

hist(Costs,Costs1,main="Histogram of  Maintenance_cost ",col="blue",
 border="darkblue",xlab="Total_cost",ylab=" ",yaxt = 'n',
 #ylim=c(0,3000),
 #xlim=c(0,max(My_Costs)),
 breaks=60)
Run Code Online (Sandbox Code Playgroud)

第一个代码给了我箱线图,但我尝试了它,它不起作用谁能告诉我如何在 R 中做到这一点?

G5W*_*G5W 5

对于基础R溶液,使用parmfrow

set.seed(1234)
Costs = rnorm(5000, 100, 20)
OUT = which(Costs %in% boxplot(Costs, plot=FALSE)$out)
Costs1 = Costs[-OUT]

par(mfrow=c(1,2), mar=c(5,1,2,1))
hist(Costs,main="Histogram of  Maintenance_cost ",col="blue",
 border="darkblue",xlab="Total_cost",ylab=" ",yaxt = 'n',
 breaks=60, xlim=c(30,170))
hist(Costs1,main="Maintenance_cost without outliers",col="blue",
 border="darkblue",xlab="Total_cost",ylab=" ",yaxt = 'n',
 breaks=60, xlim=c(30,170))
Run Code Online (Sandbox Code Playgroud)

有和没有异常值的直方图