I produced a set of 2 contour lines for 6 different individuals. The contours for each individual were originally stored in a single list which contained 6 separate SpatialLinesDataFrames (one per individual).
I used NewDf <- do.call(rbind, OriginalList)
to combine these into a single SpatialLinesDataFrame so that I can plot them on a single map with geom_path. NewDf
now returns this structure:
> NewDf
class : SpatialLinesDataFrame
features : 12
extent : .....
crs : ....
variables : 2
names : level, Individual
min values : 0.5, 21545
max values : 0.95, 32156
I can plot all contours using this:
ggplot()+
geom_path(data = NewDf, aes(x = long, y = lat, group = group)
but I want to color each set by Individual
. I find that you can access the factor Individual
using NewDf@data$Individual
, but I cannot figure out how to refer to this in the ggplot
call (e.g. ggplot()+geom_path(data = a, aes(x = long, y = lat, group = group, col = data$Individual))
does not work)
How do you access factors stored in a SpatialLinesDataFrame for mapping aesthetics in ggplot?