将轴添加到 ggplot facet_wrap 直方图

Add axis to ggplot facet_wrap histograms

我正在尝试创建一系列在轴上具有相同范围的直方图,并且对于 xy

都位于零截距的关键轴
mydat1 <- mydat + geom_histogram(binwidth = 5) + facet_wrap(~V2, scales = "free") + theme(axis.line.x = element_line(colour = "black", size = 0.05), axis.line.y = element_line(colour = "black", size = 0.05)) + scale_x_continuous(expand = c(0,0)) + scale_y_continuous(expand = c(0,0))

添加 + ylimxlim 以尝试将轴限制在相同的范围内似乎不起作用。

谁能告诉我哪里做错了?

This is what I want to produce but I need y to range from 0-15 and x from 0-400

你可以使用

scale_y_continuous(limits = c(0, 15))

scale_x_continuous(limits = c(0, 400))

这个有用吗?

马里奥的解决方案与扩展功能结合使用时有效,即

scale_x_continuous(expand = c(0,0), limits = c(0,400)
scale_y_continuous(expand = c(0,0), limits = c(0,15)