How make matching X-axis in histogram with marginal boxplot?
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)
One solution would be to set ylim=
in boxplot()
to the same range as xlim=
in 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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With