I am trying to plot a shapefile using its data as fill. When trying this, I, unfortunately, run into the error Aesthetics must be either length 1 or the same as the data (8112701): fill
My data is a 284 long SpatialPolygonsDataFrame, with the format
nations
@data
$OBJECTID (numeric)
$CNTRY_NAME (chr)
$CNTRY_CODE (chr)
$BPL_CODE (chr)
$deaths (numeric)
$cases (numeric)
@polygons
list of all polygons
The code I am trying to use is:
ggplot() +
geom_polygon(data=nations, aes(x=long,y=lat,group=group,fill=nations@data$cases)) +
theme_void()
The backtrace is
1. base `<fn>` (x)
2. ggplot2:::print.ggplot(x)
4. ggplot2:::ggplot_build.ggplot(x)
5. ggplot2 by)layer(function(l, d) l$compute_aesthetics(d, plot))
6. ggokit2 f(l= layers[[i]], d=date[[i]]])
7. l$compute_aestehetics(d, plot)
8. ggplot2 f(..., self=self)
9. ggplot2:::check_aesthetics(evaled, n)
Error in check_aesthetics(evaled, n)