I am trying to create a function that will enable me to plot a series of data frames. I am trying to set the title of my plot to a variable that will change based on a variable indicating risk factor.
This is the set-up of a data frame for smoking and a data frame for second hand smoke exposure from riskf (original data frame)
smoking <- df.maker(subsetF$Smoking, subsetM$Smoking)
second_smoking <- df.maker(subsetF$Second.hand.smoke.exposure,
subsetM$Second.hand.smoke.exposure
plot_function <- function(risks, riskf){
plot <- ggplot(risks, aes(provinces, value )) + geom_bar(aes(fill = variable),
position = "dodge", stat="identity") + scale_fill_discrete(name="Gender") +
xlab("Provinces and Territories") + ylab("Percentage(%)") + ggtitle("") +
theme_bw() + theme(panel.border = element_blank()) + theme(plot.title
= element_text(size=20), axis.title.x = element_text(size=14),
axis.title.y = element_text(size=14)) + geom_hline(yintercept=mean(risks[, 3]))
return(plot)
}
plot_function(smoking)
When I plug in smoking for risks, I want my title to be "Smoking by Province in Canada 2014", and if I plug in second_smoking for risks, I want the title to be "Second Hand Smoke by Province in Canada 2014", etc...