views:

51

answers:

2

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 point 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?

+8  A: 
plot(for_x_axis, for_y_axis, pch = ifelse(count > 0, "x", "o"))
mdsumner
This is much better than my suggestion, thank you!
Roman Luštrik
@mdsummer: Thanks so much. Is there a way to add colors. e.g. "x" as "red" and "o" as "green".
neversaint
@neversaint: Same idea `plot(for_x_axis, for_y_axis, pch = ifelse(count > 0, "x", "o"), col = ifelse(count > 0, "red", "green"))`
nico
+1  A: 

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)
Roman Luštrik