I'm trying to generalize a set of plots I regularly need through a function - I have trouble in getting some aspects right in there.
myCustomScatter <- function(df, col_x, col_y, col_z){
p1 <- ggplot(df, aes(x=df[,col_x]))
p1 <- p1 + geom_point(aes(y=df[,col_y], color=df[,col_z]))
p1 <- p1 + scale_x_continuous(name=colnames(df)[col_x])
p1 <- p1 + scale_y_continuous(name=colnames(df)[col_y])
return(p1)
}
df1 <- data.frame(a=seq(1.1,9.9,1.1), b=seq(0.1,0.9,0.1), c=rev(seq(10.1, 99.9, 11.1)))
myCustomScatter(df1, 1, 2, 3)
This gives the following plot as expected.
I need the color ranges to be discrete based on
df[,3]
values- I needblue
for value > 90,green
for 90 >= value > 70,yellow
for 70 >= value > 55,orange
for 55 >= value > 25 &red
for value <= 25 - how do I specify this ?I need the title of the legend instead of
df[,col_z]
to bec
which I can get throughcolnames(df1)[3]
- how do I specify this ?