I have the following function which runs correctly:
plot_agg <- function(df, group_type, x_label, y_axis) {
ggplot(df, aes_string(x = colnames(df)[1], y = colnames(df)[4], group = colnames(df)[3], fill=colnames(df)[3])) +
geom_bar(stat = "identity", position = "dodge")
}
}
When I enter an if statement, however, as follows:
plot_agg <- function(df, group_type, x_label, y_axis) {
if (y_axis = "wins") {
ggplot(df, aes_string(x = colnames(df)[1],
y = colnames(df)[4],
group = colnames(df)[3],
fill=colnames(df)[3])) +
geom_bar(stat = "identity", position = "dodge")
}
}
it does not even load and gives me the following error:
Error: ggplot2 doesn't know how to deal with data of class function.
Any thoughts on why an if statement would cause this?