### Name: points ### Title: Add Points to a Plot ### Aliases: points points.default pch ### Keywords: aplot ### ** Examples require(stats) # for rnorm plot(-4:4, -4:4, type = "n")# setting up coord. system points(rnorm(200), rnorm(200), col = "red") points(rnorm(100)/2, rnorm(100)/2, col = "blue", cex = 1.5) op <- par(bg = "light blue") x <- seq(0,2*pi, len=51) ## something "between type='b' and type='o'": plot(x, sin(x), type="o", pch=21, bg=par("bg"), col = "blue", cex=.6, main='plot(..., type="o", pch=21, bg=par("bg"))') par(op) ##-------- Showing all the extra & some char graphics symbols --------- 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() pchShow(c("o","O","0"), cex = 2.5) pchShow(NULL, cex = 4, cextext = 0, main = NULL) ## No test: ## ------------ test code for various pch specifications ------------- # Try this in various font families (including Hershey) # and locales. Use sign=-1 asserts we want Latin-1. # Standard cases in a MBCS locale will not plot the top half. TestChars <- function(sign=1, font=1, ...) { if(font == 5) { sign <- 1; r <- c(32:126, 160:254) } else if (l10n_info()$MBCS) r <- 32:126 else r <- 32:255 if (sign == -1) r <- c(32:126, 160:255) par(pty="s") plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="", xaxs="i", yaxs="i") grid(17, 17, lty=1) for(i in r) try(points(i%%16, i%/%16, pch=sign*i, font=font,...)) } TestChars() try(TestChars(sign=-1)) # needs MBCS support TestChars(font=5) # Euro might be at 160. Mac OS has apple at 240. ## End(No test)