Hello all,
Thank you for taking the time to help
ISSUE
- Need lines in legend that read “Mason County” and “State” with color
- Could also use help with reducing the right scale and have lines follow that scale reduction
- (Fake data)
Example code
-
``` r pacman::p_load(rio,here, skimr, janitor,epikit,lubridate,parsedate, zoo,tidylog, flextable, gtsummary,scales,ggExtra, gghighlight,ggsurveillance,rstatix,readxl,reprex, datapasta, forecast,BiocManager, ggplot2, tidyverse) data <- tibble::tribble( ~disease, ~year, ~geo, ~cases, ~rate, "HIV Diagnosis", 2019, "Mason County", 5, 7.1, "HIV Diagnosis", 2020, "Mason County", 7, 8.9, "HIV Diagnosis", 2021, "Mason County", 3, 10, "HIV Diagnosis", 2019, "State", 1, 6.8, "HIV Diagnosis", 2020, "State", 5, 7.1, "HIV Diagnosis", 2021, "State", 6, 6.2 ) HIVdx<- data %>% filter (geo == "State") HIVdxM <- data %>% filter (geo == "Mason County") ggplot ()+ geom_col(data=HIVdxM, aes( x = year, y = cases), fill = "#007777", width = .75)+ geom_line(data=HIVdxM,aes ( x = year, y = 1*rate), group = 1,, col ="#B22E0C", size = 2 )+ geom_line(data=HIVdx,aes ( x = year, y = 1*rate), group = 1,, col ="#002517", size =2 )+ scale_y_continuous(sec.axis = sec_axis(~.*1, name="Case Rate per 100,000"))+ labs( # add plot labels, title, etc. x = "Year Diagnosed", y = "Cases", title = "Mason County HIV New Diagnosis 2019-2023") + theme_minimal()

