Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在同一窗口中显示两个直方图,但在R中显示不同的绘图?_R_Plot_Histogram - Fatal编程技术网

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

如何在同一窗口中显示两个直方图,但在R中显示不同的绘图?,r,plot,histogram,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

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

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)
第一个代码给了我框图,但我尝试了hist它不工作
有谁能告诉我如何在R中执行此操作吗?

对于多个绘图,您应该使用
ggplot2
facet\u wrap
。以下是一个例子:


对于基本R解决方案,将
par
mfrow
一起使用

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@ssssoooo,如果使用ggplot2,则确实需要将两个表与数据帧堆叠在一起。您的表格将是:价值|标签xx |成本xx |成本。。。xx |成本1 xx |成本1。。。。然后您
facet\u wrap(~label)
,ggplot two将知道您想要使用label作为facet条件。