Create a map with colored polygons and coordinate points by using a .shp file in combination with another dataframe with coordinates

后端 未结 1 1400
时光取名叫无心
时光取名叫无心 2021-01-29 03:37

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 nee

相关标签:
1条回答
  • 2021-01-29 04:32

    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().

    0 讨论(0)
提交回复
热议问题