Dataframe (borrowed from here):
df.test <- data.frame(id = rep(1:6, each = 50), x = rnorm(50*6, mean = 10, sd = 5),
y = rnorm(50*6, mean = 20, sd = 10),
z = rnorm(50*6, mean = 30, sd = 15))
Plot:
library(ggplot2)
ggplot(df.test, aes(x)) + geom_histogram() + facet_wrap(~id)
Request for assistance: I'd like to superimpose onto each of the facets the histogram of the entire data, to provide immediate comparison of each facet with the total dataset, if possible I'd like the whole dataset shown as a freq_poly():
ggplot(df.test, aes(x)) + geom_freqpoly()
You can exclude the facetting variable from the call to geom_freqpoly
ggplot(df.test, aes(x)) + geom_histogram() + facet_wrap(~id) +
geom_freqpoly(data = df.test[, "x", drop = FALSE], col = "red")
The following just removes the id column from the data of geom_freqpoly.
ggplot(df.test, aes(x)) + geom_histogram() + facet_wrap(~id) +
geom_freqpoly(data=df.test[-1])
This makes it appear in all facets:
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