rplotutf-8colorspch

Using UTF-8 codes for use in intToUtf8() in R?


I'm trying to use UTF-8 code to put a symbol in some text in an R figure. If I wanted a black circle, I could use the code intToUtf8(9679). Where can I find a database that lists the values for other symbols? I want to find the code to create a red circle (i.e., pch=16, col="red"), but I can't find a list of what all of the unicode values are for specific symbols.

# example R code
x <- 1:10
y1 <- rnorm(10, x*2, 0.5)
y2 <- rnorm(10, x, 0.5)
plot(x, y1, xlab='x-value', ylab='', pch=16)
points(x, y2, pch=16, col='red')
mtext(paste0('value for y1 (', intToUtf8(9679), ') and y2 (',    intToUtf8(9679), ')'), side=2, line=2)
# except that I want the second black circle in the axis label to be a red circle

Thank you for your help, Mikey


Solution

  • Here is the solution I ended up using. It's not the most efficient, but it works:

    x <- 1:10
    y1 <- rnorm(10, x*2, 0.5)
    y2 <- rnorm(10, x, 0.5)
    plot(x, y1, xlab='x-value', ylab='', pch=16)
    points(x, y2, pch=16, col='red')
    mtext('value for y1 (\u25CF) and y2 (  )', side=2, line=2)
    mtext('                                   \u25CF', side=2, line=2, col='red')
    
    # alternatively, the following would also work in place of line 6
    mtext(paste0('value for y1 (', intToUtf8(9679),' and y2 (  )'), side=2, line=2)
    

    If you want to find more unicode character information for your specific symbol, you can look here.

    Thank you lukeA for your help with this.