I have a scatter plot in R (with ggplot2). The data has a numeric column (let's call it bin) which can contain various integer 开发者_JAVA技巧values or null.
I would like to colour the points with non-null bin values differently from the others. I do not want to one colour per value of bin, that would be too noisy. Just simply, say, red for those with a non-null bin and black for the others.
qplot has a colour attribute, but I don't know how to express a condition like colour = bin != null ? "red" : "black"
You could define the color first:
color <- rep("black", length(bin))
color[is.null(color)] <- "red"
Otherwise you can use an ifelse statement:
colour=ifelse(is.null(bin), "red", "black")
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论