I want to plot a bar graph together with a line graph (secondary axis). The observation values for the line graph appears but the line doesnt appear as shown in diagram. I think maybe my transformation is wrong? Below are my code.
Year <- c( "2017", "2018","2019","2020")
Response <- c(6, 10, 6, 2)
Rate <- c(0.22, 0.36, 0.21, 0.07)
df <- data.frame(month, Response,Rate)
#Chart
library(ggplot2)
ggplot(df) +
geom_bar(aes(x=Year, y=Response),stat="identity", fill="yellow",colour="sienna3")+
geom_text(aes(label=Response, x=Year, y=1.09*Response),colour="black")+
geom_line(aes(x=Year, y=Rate*20),colour="black",stat="identity")+
geom_text(aes(label=Rate, x=Year, y=Rate*25), colour="black")+
scale_y_continuous("# Cases") +
xlab("Month") +
theme(axis.text = element_text(size = 13)) +
theme(axis.title = element_text(size = 14)) +
scale_y_continuous(sec.axis = sec_axis(~./25, name="Incidence rate/100000"))