Combine your data sets result_A
and result_B
into a single dataset, where the thing these differences are is specified as some factor, e.g. "thing":
result_A$thing <- "A"
result_B$thing <- "B"
result_AB <- rbind(result_A, result_B)
Then instead of calling two datasets with separate calls to geom_density
, specify it once with fill = thing
and specify your colours and alphas manually, e.g.:
ggplot(data = result_AB, aes(x = log(cap_universal))) +
geom_density(aes(fill = thing,
alpha = thing)) +
scale_fill_manual(values = c("light blue", "purple")) +
scale_alpha_manual(values = c(1, 0.25)) +
# assuming here that the "result_A" data will plot first as "A" should
# order before "B" in factors, though can't test w/out yr data
xlab("Complete Automation Probability") +
ylab("Density")
This should produce a legend showing what colour your factors "A" and "B" are, which I assume is what you're after.
This is more in-line with the philosophy of ggplot2
. However it might also work if you wrap both your fill
calls inside aes
, e.g. geom_density(aes(fill = "lightblue"))
. (It's impossible to test this though, because you haven't got a reproducible example above)