Print PCH Shapes in R

Viewed 68

When plotting points in R, the shape the marker will take in the plot can be specified by setting the "symbol" and "symbols" variable to the required plotting character ("pch") when plotting. In other words, plotting can be done by having something along the lines of

        myX = c(1:3);
        myY = c(1:3);

        
        p <- plot_ly() %>%
            add_trace(
                type = "scatter",
                mode = "markers",
                x = myX,
                y = myY,
                symbol = c(0, 1, 2), #Comment: PCH characters specified here
                marker = list(line = list(width = 1.5)),
                symbols = c(0, 1 ,2), #Comment: PCH characters specified here
                size = 10,
                showlegend = F
            ) 

The above works fine but is there any way I can obtain these marker symbols as strings, I would like to be able to do something along the lines of

firstMarkerString <- paste( "Marker number zero is ", getMarker(pch = 0));
secondMarkerString <- paste( "Marker number one is ", getMarker(pch = 1));
1 Answers

You cannot get these markers as string. Ultimately they are drawn directly by the graphics engine and are build up manually from circles, squares, polygons and such.

The function responsible for this is currently GESymbol defined in src/main/engine.c.

What you can do is making a legend that combines strings with symbols in the plot, but the result is a picture and not a string.

Otherwise you can only look for a font that offers similar symbols I'm afraid.

Related