0

I'm very used to ggplot2, but not so much sf. I've converted a spatialpolygonsdataframe to a sf using st_as_sf(), and now I'm trying to plot it. Why is my variable 'test' a matrix? Have I done something wrong?

class(wards)
[1] "sf"         "data.frame"

names(wards)
 [1] "wd16cd"                  "wd16nm"                  "lad16nm"                
 [4] "test"                    "2015_no2_total"          "2020_no2_total"         
 [7] "2025_no2_total"          "2030_no2_total"          "2011_pm25_total"        
 [10] "2011_pm25_secondary"     "2011_pm25_residual_salt" "2015_pm25_total"        
 [13] "2015_pm25_secondary"     "2015_pm25_residual_salt" "2020_pm25_total"        
 [16] "2020_pm25_secondary"     "2020_pm25_residual_salt" "2025_pm25_total"        
 [19] "2025_pm25_secondary"     "2025_pm25_residual_salt" "2030_pm25_total"        
 [22] "2030_pm25_secondary"     "2030_pm25_residual_salt" "geometry"               

 class(wards$test)
 [1] "matrix"

 ggplot(wards) +
 +   geom_sf(aes(fill = test))

 Error: Column `fill` must be a 1d atomic vector or a list

Thanks, James

TheRealJimShady
  • 777
  • 3
  • 9
  • 24
  • 1
    This question is difficult to answer as is it written. You will be much more likely to receive a useful answer with a minimal reproducible example: [How to make a great R reproducible example?](http://stackoverflow.com/questions/5963269) – Axeman May 02 '18 at 12:12
  • I've kind of fixed it. Like this... ggplot(wards) + + geom_sf(aes(fill = test[,1)) – TheRealJimShady May 02 '18 at 12:58

0 Answers0