Skip to content
Prev 305552 / 398506 Next

plotting points on a map, assigning vectors to values from dataset

You didn't include the data so we can't really test anything, but
you can simplify things quite a bit by replacing the pch= and bg= 
lines with 

pch <- c(24, 23, 22, 21)
bg <- c("grey24", "black", "grey77", "white")

map$number is a factor which means your categories default to 
alphabetical order so the first category (factor code 1) is 
fourfive and the second category (factor code 2) is sixseven.
The above lines take this into account. 

Then replace the whole for loop (you really need to learn about
vectorization in R) with a single function call:

points(map$longitude, map$latitude, pch=pch(as.numeric(map$number)),
   col="black", bg=bg(as.numeric(map$number)), cex=1.5)

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352