Good evening everyone, this is my first post on stack overflow so I hope you'll forgive me for my level of english and if I made some "rules" mistake.
I am working, for a school project, on some cool visualization with ggplot2 on the dataset Covid19.
What I am aiming to do is plotting a curve that is colored regarding a certain factor, here (stay_home_restrictions), and I managed to produce said plot but I'm quite dissatisfied with the colors and would like to change them.
Here is my code :
#libraries
library(COVID19)
library(naniar)
library(ggplot2)
library(tidyr)
library(dplyr)
library(lubridate)
library(hms)
library(scales)
library(RColorBrewer)
cov1=covid19(level = 1) #Original df
#Grouping by country and keeping what I feel useful
cov1conf2=cov1%>%
group_by(administrative_area_level_1)%>%
select(date,deaths,confirmed,recovered,people_vaccinated,people_fully_vaccinated,workplace_closing,
cancel_events,gatherings_restrictions,transport_closing,stay_home_restrictions,
internal_movement_restrictions,international_movement_restrictions,facial_coverings,population)%>%
mutate(confirmed_pct=round((confirmed/population)*100, 5),deaths_pct=round((deaths/population)*100, 5),
people_vaccinated_pct=round((people_vaccinated/population)*100, 5),
people_fully_vaccinated_pct=round((people_fully_vaccinated/population)*100, 5))
#reducing number of country to those I chose to study
cntry_of_interest=cov1conf2%>%
filter(administrative_area_level_1 %in% c("United States","France","China","Japan"))
#Data from France
France <-cntry_of_interest%>%
filter(administrative_area_level_1=="France")%>%
mutate(day=format(date,"%d"),month = format(date, "%m"), year = format(date, "%Y"))
#Daily number of confirmed cases and deaths
France_daily<-France%>%
mutate(daily_confirmed=c(France$confirmed[1],diff(confirmed)),
daily_deaths=c(France$deaths[1],diff(deaths)))%>%
group_by(year)
#Year 2020
F2020 = France_daily%>%filter(year==2020)
#Plot code !
plot<-ggplot(F2020,aes(x = date , y = daily_confirmed))+
geom_line(color=as.factor(abs(F2020$stay_home_restrictions)+1))+
scale_fill_brewer(palette="Set1")+
scale_x_date(date_breaks = '1 month',
labels = date_format("%b-%y"))+
labs(title = "Percentage of cummulative number of cases in France",
x = "Date",
y = "percentage of confirmed cases",
fill= "stay_home_restrictions")
plot
You'll tell me that this post already exists and that I just need to add a scale_fill_manual but the thing is that my color=as.factor(stay_home_restrictions) is mapped in my geom_line() and the programm just refuses to change the colors with either scale_fill_manual or scale_color_brewer.
I didn't put my color=as.factor(stay_home_restrictions) in the main ggplot2 object (not sure it is called that way) because this would render a plot of 3 superimposed continuous curves (1 for each value of my factor) ! See : Why i didn't put the color=as.factor in main aes
What should I do in order to change the color of the first plot? Thank by advance for your kind support,