The colors in my density plot are wrong! I can't figure out why.
Here is my data: https://pastebin.com/0jqHgvxx
data %>%
ggplot(aes(x=amountremain, color=black)) +
geom_density()
When I check the raw data, I see that the red peak at x=0 is correct but the max x value corresponds to the a y-value for the red not blue line.
The max x value for black = TRUE is 162414.6, max x for black = FALSE is 253021.3 so the tail should be red not blue.
b <- unclass(density(data$amountremain[data$black==FALSE]))
max(b$y)
max(b$x)
[1] 0.0003079798
[1] 253021.3
a <- unclass(density(data$amountremain[data$black==TRUE]))
max(a$y)
max(a$x)
[1] 0.0002832889
[1] 162414.6