This works:
plot_interaction_term = function(df)
{
print(ggplot(data=df, mapping=aes(y=new_confirmed, x=cumulative_vaccine_doses_administered_pfizer, color=cut(cumulative_vaccine_doses_administered_moderna, breaks=c(-Inf, Inf))))
+ geom_point()
+ geom_smooth(method = "lm", se=FALSE))
}
plot_interaction_term(df)
This doesn't work:
plot_interaction_term = function(df, explanatory_variable1, explanatory_variable2)
{
print(ggplot(data=df, mapping=aes(y=new_confirmed, x=explanatory_variable1, color=cut(explanatory_variable2, breaks=c(-Inf, Inf))))
+ geom_point()
+ geom_smooth(method = "lm", se=FALSE))
}
plot_interaction_term(df, "cumulative_vaccine_doses_administered_pfizer", "cumulative_vaccine_doses_administered_moderna")
ERROR: Error in cut.default(explanatory_variable2, breaks = c(-Inf, Inf)) : 'x' must be numeric
2nd try:
plot_interaction_term(df, cumulative_vaccine_doses_administered_pfizer, cumulative_vaccine_doses_administered_moderna)
ERROR: Error in FUN(X[[i]], ...) : object 'cumulative_vaccine_doses_administered_pfizer' not found
3rd try:
plot_interaction_term(df, df["cumulative_vaccine_doses_administered_pfizer"], df["cumulative_vaccine_doses_administered_moderna"])
Error in cut.default(explanatory_variable2, breaks = c(-Inf, Inf)) : 'x' must be numeric
How do I get this to work?
print(df)