Monday, May 5, 2014

Useful R graphics link


http://stackoverflow.com/questions/14698616/when-should-i-use-geom-map

# solution 1
colnames(pointData) < - c('long','lat') # makes consistent with county_map
pointData$group < - 1 # ggplot needs a group to work with
county_map$value < - sapply(1:nrow(county_map),
                           function(x) round(runif(1, 1, 8), 0)) # for colours

ggplot(county_map, aes(x = long, y = lat, group = group)) +
    geom_polygon(aes(fill = value)) +
    coord_map() +
    geom_point(data = pointData, aes(x = long, y = lat), shape = 21, fill = "red")




# solution 2

map1 < - ggplot(countyData) +
  geom_map( map = county_map, aes(map_id = id,fill = value), 
            colour = "black") + coord_map() +
  expand_limits(x = county_map$long, y = county_map$lat)
  map1 + geom_point(mapping = aes(xx, yy), data = pointData)
 
 

No comments: