I looked at other solutions but cannot get a logical within ggplot to work correctly. I have the following function. A dataframe is passed alongwith two columns to plot as a scatter plot.
scatter_plot2 <- function(df, xaxis, yaxis){
b <- ggplot(data = df, aes_string(xaxis, yaxis), environment = environment())
gtype <- geom_point(aes(alpha = 0.2, color = yaxis > 0))
sm <- geom_smooth(formula = xaxis ~ yaxis, color="black")
b + gtype + sm + theme_bw()
}
which I call using :
scatter_plot2(train_df, "train_df$signal", "train_df$yhat5")
===
The color = yaxis > 0
is intended to plot points above (yaxis) 0 in "green" and ones below in "red". While i'm able to get the string names to correctly display on the axis, I'm not able to get the logical to work correctly.
Please help.
