Skip to content Skip to sidebar Skip to footer

Create A Map With Colored Polygons And Coordinate Points By Using A .shp File In Combination With Another Dataframe With Coordinates

I have the following map boundaries in this .gdb folder and here I have a csv which contains the variables that I want to plot and the coordinates of the points that need to be dis

Solution 1:

Your file still doesn't download.

I can give you a generic guide to use ggplot2 to make a map. This will draw the polygons and the points.

You need to modify the Spatial_DataFrames with fortify() to get them into a format ggplot2 can use.

library(ggplot2)

hs_b2 <- fortify(hs_bounds) #or instead of "hs_bounds", "tracts" or whatever your polygon #is called. If that doesn't work you need "<-as.data.frame()". #Make sure the output has a separate column for x and y.#repeat for the points (student) object.
student_2 <- fortify(<studentpointsobject>) 

ggplot(data=<student_2>, aes(x=x,y=y)) +  
    geom_polygon(data=hs_b2, aes(x=long, y=lat, group=group) ,        #this will create the polygon
    colour="grey90", alpha=1,               #one of your color options for polygons
    fill="grey40") +                        #one of your color options for polygons
    theme(axis.ticks.y = element_blank(),axis.text.y = element_blank(), # get rid of x ticks/text
      axis.ticks.x = element_blank(),axis.text.x = element_blank()) +  # get rid of y ticks/text
    geom_point(aes(color="grey20"))         #to get the points drawn. mess with "fill" and "color"   

You can customize the plot with 'color' or 'fill' in the aes().

Post a Comment for "Create A Map With Colored Polygons And Coordinate Points By Using A .shp File In Combination With Another Dataframe With Coordinates"