我如何在相同的 window 中显示两个直方图,但在 R 中显示不同的图?
how can i show two histogram in same window but different plots in R?
我想在我的直方图上显示移除异常值的效果,所以我必须将两个直方图一起绘制。
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 中做到这一点?
对于多个地块,您应该使用 ggplot2
和 facet_wrap
。这是一个例子:
Plot several histograms with ggplot in one window with several variables
对于基础 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))
我想在我的直方图上显示移除异常值的效果,所以我必须将两个直方图一起绘制。
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 中做到这一点?
对于多个地块,您应该使用 ggplot2
和 facet_wrap
。这是一个例子:
Plot several histograms with ggplot in one window with several variables
对于基础 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))