Skip to content

Instantly share code, notes, and snippets.

@maptracker
Last active January 21, 2016 14:01
Show Gist options
  • Save maptracker/e23b3f3712065677ba24 to your computer and use it in GitHub Desktop.
Save maptracker/e23b3f3712065677ba24 to your computer and use it in GitHub Desktop.
Visualize #R #pch (plot characters) used in #points
# From @Greg Snow https://stackoverflow.com/a/3740473
# Plots a grid with default tokens on bottom two rows, characters in others
png(filename="GregSnow.png", width = 600, height = 600)
plot( 0:15, 0:15, type='n', main = "pch values by Greg Snow" )
points( (0:255)%% 16, (0:255) %/% 16, pch=0:255, font=5, cex = 2 )
dev.off()
# From the R help for ?points
png(filename="PointsHelp.png", width = 600, height = 600)
pchShow <-
function(extras = c("*",".", "o","O","0","+","-","|","%","#"),
cex = 3, ## good for both .Device=="postscript" and "x11"
col = "red3", bg = "gold", coltext = "brown", cextext = 1.2,
main = paste("plot symbols : points (... pch = *, cex =",
cex,")"))
{
nex <- length(extras)
np <- 26 + nex
ipch <- 0:(np-1)
k <- floor(sqrt(np))
dd <- c(-1,1)/2
rx <- dd + range(ix <- ipch %/% k)
ry <- dd + range(iy <- 3 + (k-1)- ipch %% k)
pch <- as.list(ipch) # list with integers & strings
if(nex > 0) pch[26+ 1:nex] <- as.list(extras)
plot(rx, ry, type = "n", axes = FALSE, xlab = "", ylab = "", main = main)
abline(v = ix, h = iy, col = "lightgray", lty = "dotted")
for(i in 1:np) {
pc <- pch[[i]]
## 'col' symbols with a 'bg'-colored interior (where available) :
points(ix[i], iy[i], pch = pc, col = col, bg = bg, cex = cex)
if(cextext > 0)
text(ix[i] - 0.3, iy[i], pc, col = coltext, cex = cextext)
}
}
pchShow()
dev.off()
@maptracker
Copy link
Author

Just wanted a static reference to lookup the integer codes used by pch for R point characters.
Via code from ?points:
pointshelp
Via StackOverflow:
gregsnow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment