When I combine two geom_freqpolys on the same chart, the one with a narrower range on the x-axis at y=0 will continue until it reaches the other one.
An example will explain this better...
library(tidyr)
library(ggplot2)
set.seed(123)
a <- rnorm(10000, 0, 1)
b <- rnorm(10000, 1, 4)
df <- data.frame(a, b)
dfl <- pivot_longer(df, cols = c(a, b),
names_to = 'distribution',
values_to = 'values')
ggplot(dfl) +
geom_freqpoly(aes(values, colour = distribution), bins = 100) +
geom_point(aes(x = min(`values`[`distribution` == 'a']), y = 0), size = 3) +
geom_point(aes(x = max(`values`[`distribution` == 'a']), y = 0), size = 3) +
scale_x_continuous(breaks = seq(-14,17,1))
ggplot() +
geom_freqpoly(data = df, aes(x = a), bins = 100, colour = 'red') +
geom_freqpoly(data = df, aes(x = b), bins = 100, colour = 'blue') +
geom_point(aes(x = min(df$a), y = 0), size = 3) +
geom_point(aes(x = max(df$a), y = 0), size = 3) +
scale_x_continuous(breaks = seq(-14,17,1))
Whether I use the long data to use one geom, or use the original data to use two seperate ones, I'm getting the undesirable result of the red line continuing beyond the black points. Is there a way to stop this from happening?

