grid of density plots with reference data plotted in each group
One option would be to split your dataframe in two, one containing the reference values, one containing the others. For the df containing the reference values we also have to drop the source
column. Then make use of two geom_density
. Removing the reference from the legend is not a big deal. Simply remove the fill aes and set your desired fill color if any as a parameter. In my code below I have simply set fill=NA
.
library(ggplot2)
df1 <- df[df$source == "ref", -2]
df2 <- df[!df$source == "ref", ]
ggplot(mapping = aes(x = value)) +
geom_density(data = df1, aes(y = ..density..), fill = NA, adjust = 1, alpha = 0.5) +
geom_density(data = df2, aes(y = ..density.., fill = source), adjust = 1, alpha = 0.5) +
facet_grid(source ~ var, scales = "fixed") +
theme_bw()