I am using background image in the plot but the colors of the plot is mixing up with the image so I would like to add an overlay semitransparent black layer to the background image so that plot colors can stand out and do not mix with the background..
I have tried adding geom_rect()
but that doesn't work well geom_rect(aes(xmin = min(date), xmax=max(date), ymin = -Inf, ymax=Inf), fill = "black", alpha = 0.3)
How can I just add a semitransparent overlay layer over the complete background image.
failed result
df
library(tidyverse)
library(lubridate)
library(ggpubr)
library(grid)
library(jpeg)
file_url1 <- "https://raw.githubusercontent.com/johnsnow09/covid19-df_stack-code/main/ts_all_long4.csv"
ts_all_long <- read.csv(url(file_url1))
ts_all_long <- ts_all_long %>%
mutate(date = as.Date(date))
without geom_rect()
:
ts_all_long %>%
filter(Country.Region == "Brazil") %>%
ggplot(aes(x = date, y = Confirmed_daily)) +
background_image(readJPEG("Covid 19 images/coronavirus-4972480_1920.jpg")) +
geom_area(size = 1, col = "#f08080", fill = "#f08080", alpha = 0.5)
with geom_rect()
:
ts_all_long %>%
filter(Country.Region == "Brazil") %>%
ggplot(aes(x = date, y = Confirmed_daily)) +
background_image(readJPEG("Covid 19 images/coronavirus-4972480_1920.jpg")) +
geom_rect(aes(xmin = min(date), xmax=max(date), ymin = -Inf, ymax=Inf),
fill = "black", alpha = 0.3) +
geom_area(size = 1, col = "#f08080", fill = "#f08080", alpha = 0.5)