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

标签 r plot histogram

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

boxplot(Costs, Costs1,
    xlab=" Costs    and    Costs after  removig outliers",
    col=topo.colors(2))

所以我尝试了这个:

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)

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

最佳答案

对于基础 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))

Histograms with and without outliers

关于r - 如何在同一窗口中显示两个直方图,但在 R 中显示不同的图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58583157/

相关文章:

r - 如何在R中一起绘制多个堆叠的直方图?

r - 在 data.frame 中有效地定位分组常量列

r - 使用 cowplot 和 ggplot2 在某些行周围绘制边框

R - 切割一个向量

python - 在直方图中找到两个最高峰的中心值Python

statistics - 求两个直方图的卷积

r - 无法在 r Shiny 的 docker 中安装 devtools

r - 如何将两个 sjp.likert (来自 sjPlot 包)生成的图合并到一个图中?

绘制大型时间序列

r - 将两个 ggplots 合并为一个具有共享图例的图