开发者

How to Plot With Different Marker ( 'x' and 'o') Based on Condition in R

I have a data that looks like this:

for_y_axis <-c(0.49534,0.80796,0.93970,0.99998)
for_x_axis <-c(1,2,3,4)
count      <-c(0,33,0,4)

What I want to do is to plot the graph using for_x_axis and for_y_axis but will mark the poin开发者_如何学Pythont with "o" if the count value is equal to 0(zero) and with "x" if the count value is greater than zero.

Is there a simple way to achieve that in R?


plot(for_x_axis, for_y_axis, pch = ifelse(count > 0, "x", "o"))


How does this sound? Adjust pch to your needs.

for_y_axis <- c(0.49534,0.80796,0.93970,0.99998)
for_x_axis <- c(1,2,3,4)
count <- c(0,33,0,4)

zerocount <- function(x) {
    ifelse (x == 0, x <- 0, x <- 1)
}

pts <- sapply(count, zerocount)
plot(for_x_axis, for_y_axis, type = "n")
points(for_x_axis, for_y_axis, pch = pts)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜