I have a specific question: How can I choose either fill or color of a ggplot according to the data of an SpatialPolygonsDataFrame-object? For example consider the following SpatialPolygonsDataFrame sf:
sf <- readShapePoly("somePolygonShapeFile")
It allows me to access the the example data field FK like:
sf$FK // or
sf@data$FK
Now, I want to prepare a simple ggplot:
p <- ggplot(sf, aes(x=long, y=lat, group=group, FK=???))
However, I don't know what to pass to FK in aes(). Experiences from gridded data frames (grid.extent(...)) made me think, I could directly put in FK=FK. This does not seem to work for SpatialPolygonsDataFrame-objects. Trying FK=sf$FK or FK=sf@data$FK is not allowed because:
Error: Aesthetics must either be length one, or the same length as the data
I guess, the solution is trivial, but I simply don't get it at the moment.