I´m creating a spatial map of trees based on x-y location using the spatstat package and the ppp function. I´ve been able to do this and the size of each point is based on tree diameter. What I haven´t been able to do, and I hope to find some help here, is to create a legend that allows me to show these different circles and also include the 6 tree species within the plot. Here is the code I´m using:
df <- subset(plots, plots$spp == "DF") # Douglas-fir
dfx <- as.numeric(as.character(df$x))
dfy <- as.numeric(as.character(df$y))
dfd <- as.numeric(as.character(df$d))
dfp <- ppp(dfx, dfy, window = owin(c(0, 100), c(0, 100)),
unitname=c("metres","metres"), marks = dfd)
par(mar = c(2, 2, 2, 2))
plot(dfp, main = "", cex = 0.8, markscale = 0.04,
bg = rgb(0.1,0.9,0.3,0.5), fg = "black")
I have a similar structure for every species in the plot (wh for Western Hemlock and the code is the same...)
Thanks!
First collect all the data into a single
pppobject usingsuperimpose. For example if you have Douglas Firdfpand Western Hemlockwhpthencreates a point pattern
Xin which each point has two mark values, the species and the diameter. For convenience, change the mark column names:Next determine the plot symbol map for the diameters (without plotting anything):
Next pick a set of colours for the different species, e.g.
Now plot the species in separate colours using the diameter scale map:
Finally plot the two symbol maps
dmapandsmapin the places you want by usingplot(dmap, add=TRUE, xlim=..., ylim=...)and so on.In future this will be automated, but it hasn't been implemented yet.