I'm trying to create a single graph with 2 superimposed smooth density plots of my numeric_var stratified for my factor_var, using Rstudio R version 3.5.1 on Mac. I always get the same error:
"Aesthetics must be either length 1 or the same as the data (): x, fill"
I've tried multiple approaches (one example below). I've also followed this guide - STHDA, removed NA and checked other questions regarding this error but I can't manage to get this working. This is what I'm trying to get:
Help please? (I'm a newbie, first question, please be kind :) )
data
mydata <- fulldata %>%
select(numeric_var,factor_var) %>%
filter(factor_var== 0 | factor_var== 1)
head(mydata)
numeric_var factor_var
1 0.6 0
2 0.7 0
3 0.7 1
4 0.9 0
5 0.6 1
6 0.7 0
plot code
ggplot(mydata, aes(x = numeric_var, fill = factor_var)) +
geom_density(alpha = 0.5)
error:
Aesthetics must be either length 1 or the same as the data (598): x, fill