Graphics Programs Reference
In-Depth Information
Taking the map in the opposite direction, say you want to only map Costco
locations for a few states. You can do that with the region argument.
map(database=”state”, region=c(“California”, “Nevada”, “Oregon”,
“Washington”), col=”#cccccc”)
symbols(costcos$Longitude, costcos$Latitude, bg=”#e2373f”, fg=”#ffffff”,
lwd=0.5, circles=rep(1, length(costcos$Longitude)), inches=0.05,
add=TRUE)
As shown in Figure 8-6, you create a bottom layer with California, Nevada,
Oregon, and Mexico. Then you create the data layer on top of that. Some
dots are not in any of those states, but they're in the plotting region, so
they still appear. Again, it's trivial to remove those in your favorite vector
editing software.
MAP WITh LINES
In some cases it could be useful to connect the dots on your map if the
order of the points have any relevance. With online location services such
as Foursquare growing in popularity, location traces aren't all that rare.
An easy way to draw lines is, well, with the lines() function. To demon-
strate, look at locations I traveled during my seven days and nights as a
spy for the fake government of Fakesville. Start with loading the data (as
usual) and drawing a base world map.
faketrace <-
read.csv(“http://book.flowingdata.com/ch08/points/fake-trace.txt”,
sep=”\t”)
map(database=”world”, col=”#cccccc”)
Take a look at the data frame by entering faketrace in your R console. You
see that it's just two columns for latitude and longitude and eight data
points. You can assume that the points are already in the order that I trav-
eled during those long seven nights.
latitude longitude
1 46.31658 3.515625
2 61.27023 69.609375
3 34.30714 105.468750
4 -26.11599 122.695313
5 -30.14513 22.851563
6 -35.17381 -63.632813
7 21.28937 -99.492188
8 36.17336 -115.180664
Search WWH ::




Custom Search