我有以下正确运行的功能:
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")
}
}
但是,当我输入if语句时,如下所示:
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")
}
}
它甚至没有加载并给我以下错误:
错误:ggplot2不知道如何处理类函数的数据。
关于为什么if语句会导致这种情况的任何想法?