Search code examples
rplotpch

Assigning pch symbols in plot


I have a plot of many omega values within which I want to highlight about 40 points among the many others. The plot argument I am using is:

plot( log( dog[ order( dog$gbm.dog ) , 8 ] ), 
     pch = ifelse( dog$refseq_mrna %in% dog_omegaplus$refseq_mrna, 2,
           ifelse( dog$refseq_mrna %in% dog_omegaminus$refseq_mrna, 12, "." ) ) )

I want to have one group of highlighted points to be triangles (pch = 2), the other group to be squares (pch = 12) and all other points dots ("."). The problem is that the plot this produces has digits where the pch symbols should be (specifically a "2" where there should be triangles and a "1" where there should be squares).

How do I designate the symbols correctly?


Solution

  • The problem here is that using "." coerces the 2's and 12's to character values. I constructed a simple test case to see what was happening and whether I could find a numeric designation that would be satisfactory:

    x <- 1:20
    
     ifelse(x < 5 , 2, ifelse(x > 15, 12, "."))
     [1] "2"  "2"  "2"  "2"  "."  "."  "."  "."  "."  "."  "."  "."  "."  "."  "."  "12" "12" "12" "12"
    [20] "12"
    
    # only return integers
    
    plot(x, pch= ifelse(x < 5 , 2, ifelse(x > 15, 12, 20)))
    

    enter image description here