我想在直方图上叠加一个直方图边框,但它们不在正确的位置
library(tidyverse)
data("iris")
iris %>%
ggplot(
aes(Sepal.Length)
) +
geom_histogram(
alpha = .5
) +
stat_bin(geom="step") +
facet_wrap(
~Species, ncol = 1
)
Run Code Online (Sandbox Code Playgroud)
返回
如何将边框与直方图对齐?
可以通过指定binwidth然后设置breaks
library(tidyverse)
data("iris")
iris %>%
ggplot( aes(Sepal.Length)) +
geom_histogram(alpha = .5, binwidth = .1) +
stat_bin(geom="step", breaks = seq(3,8, .1)) +
facet_wrap( ~Species, ncol = 1)
Run Code Online (Sandbox Code Playgroud)