4
I have a bar graph in the R with percentage variation, I would like the negative percentage values to be red, as in this example:
But my chart is getting this way:
Code I am using:
library(tidyverse)
dados <- read_delim("~/Downloads/arquivo_geral.csv",
";", escape_double = FALSE, trim_ws = TRUE)
dados <- dados[,-1]
variacaoCasosnovos <- dados %>%
mutate(dif_semanal = c(rep(NA, 7), diff(casosNovos, 7)),
percentual_dif = dif_semanal / lag(casosNovos, 7)) %>%
select("percentual_dif")
dados <- cbind(dados, variacaoCasosnovos)
dados %>%
filter(estado == "SP", data > "2020-03-31") %>%
mutate(cor = as.factor(ifelse(variacaoCasosNovos > 0, yes = 1, no = 0))) %>%
ggplot() +
geom_col(aes(x = data, y = variacaoCasosNovos), na.rm = TRUE, color = "black", fill = "#ADD8E6") +
geom_hline(yintercept = 0) +
guides(fill = FALSE) +
labs(x = "", y = "Variação") +
ggtitle("Variação inter-semanal de novos casos confirmados - Brasil") +
scale_fill_manual(values = c("firebrick", "dodgerblue4"))
Database: https://covid.saude.gov.br/