3
I have the following data and would like to create a chart with the ggplot2::geom_area()
with different colors for the positive and negative values. However, I am getting an error and I am not being able to solve it. Could someone help?
dados <- structure(list(year = c(2020, 2020, 2020, 2020, 2020, 2020, 2020,
2020, 2020, 2020, 2020, 2020), month = structure(1:12, .Label = c("January",
"February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December"), class = "factor"),
diff = c(167916.47, 58945.82, 432269.2, 532863.2, -434494,
-493142.3, -50919.75, -207215.3, -278524.84, -77664.68, 161101.79,
144261.69), signal = c("pos", "pos", "pos", "pos", "neg",
"neg", "neg", "neg", "neg", "neg", "pos", "pos")), row.names = c(NA,
-12L), class = c("tbl_df", "tbl", "data.frame"))
When 'plotting' the data without the geom_area(aes(fill = signal))
, the graph comes out correct:
Then when I use the argument fill
to try to fill in positive and negative with different colors
dados %>%
ggplot(aes(x = month, y = diff,
group = 1))+
geom_area(aes(fill = signal))
get the following error: Erro: Aesthetics can not vary with a ribbon
.
Did anyone know where the bug is? I tried with different data of these (with continuous variable on the X axis) and I got it, but not with these. Thank you.
This answers your question? Geom_area with different filling colors
– Carlos Eduardo Lagosta
That’s exactly what I want, I came to see this question/ answer, but I could not transpose the logic to my data. I’ll try/study some more. Thanks!
– r_rabbit