Search code examples
rshapefiler-sf

Plotting 1 attribute of a shp file in R


I'm trying to select & plot just one of these 9 attributes from my shape file, but nothing seems to work. Could you help?

enter image description here


Solution

  • It helps if you make a fully reproducible example so that fixers can run the code and be certain that they have resolved the issue.

    Here is an example that you will have to modify for your own needs.

    library(sf)
    fname <- system.file("shape/nc.shp", package="sf") # read a shape file that comes with the sf package
    nc <- st_read(fname)
    plot(nc)  # plot all the data
    

    enter image description here

    plot(nc['AREA']) # plot one of the attributes
    

    enter image description here