R中的边缘箱线图的直方图

And*_*ndy 5 r histogram boxplot

如何使直方图中的X轴与边缘箱图匹配?

data <- rnorm(1000)
nf <- layout(mat = matrix(c(1,2),2,1, byrow=TRUE),  height = c(1,3))
layout.show(nf)
par(mar=c(5.1, 4.1, 1.1, 2.1))
boxplot(data, horizontal=TRUE,  outline=FALSE)
hist(data)
Run Code Online (Sandbox Code Playgroud)

Did*_*rts 11

一个解决办法是设置ylim=boxplot()以相同的范围内xlim=hist().

set.seed(123)
data <- rnorm(1000)
nf <- layout(mat = matrix(c(1,2),2,1, byrow=TRUE),  height = c(1,3))
par(mar=c(5.1, 4.1, 1.1, 2.1))
boxplot(data, horizontal=TRUE,  outline=FALSE,ylim=c(-4,4))
hist(data,xlim=c(-4,4))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述