ggforce
ggforce copied to clipboard
`geom_mark_rect` does not work with histograms
I'd like to use geom_mark_rect
with a histogram, but this doesn't seem to work as it expects a y
aesthetics. Here is a reprex:
library(ggplot2)
library(ggforce)
library(dplyr)
#>
#> Attachement du package : 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
df <- cars %>%
mutate(category = if_else(speed < 15, "a", "b"))
ggplot(df, aes(x = speed)) +
geom_histogram() +
geom_mark_rect(aes(label = category))
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Error: geom_mark_rect requires the following missing aesthetics: y
I'm using ggforce 0.3.1 and ggplot2 3.2.1.
I would also like to know how to accomplish this
Since I don't know exactly how you intent to use it I can give a specific answer, but setting stat = "bin"
in geom_mark_rect()
should allow you access to the same values as those used in the geom_histogram()
layer