25.4.14

Displaying movement map in R as raster

So I've been busy trying to output suitable information from my model to demonstrate the area sin which agents are moving. I want to get some idea of how well used the map is, and if agents are able to successfully negotiate the central section of the landscape where heterogeneity is highest.

I've outputted a text file that has the number of steps taken in each grid cell and converted this to an ASCII file, replacing all commas with spaces and adding the relevant information at the start of the file as below:


ncols         608
nrows         506
xllcorner     299006.96538007
yllcorner     1898128.1510276
cellsize      100
NODATA_value  0

I can now read this into R with the following:
(which requires several packages - raster, rgdal and scales)


Map1 <- raster ("/Users/aw4g09/Dropbox/ThesisChapters/CorridorLandscapePaper/simulationData/RawData/long_corridorModelOutput/GISMovementMap_1.txt")

and display with several options:
plot(Map1)
or

map.spdf <- as(Map1, "SpatialPixelsDataFrame")
map.df <- as.data.frame(map.spdf)
head(map.df)
gMap <- ggplot(map.df, aes(x=x, y=y)) + geom_tile(aes(fill=layer)) + coord_equal()
gMap <- gMap + theme(panel.background = element_rect(fill='white'))
gMap <- gMap + scale_fill_gradient2(limits = c(0, 30000), low=muted("green"), mid="red", high="white", midpoint=15000)
gMap
This latter option allows me to manipulate the legend extent, choose gradient colours etc.

I also found a VERY cool way to generate a 3D plot of the raster which can be manipulated. This requires some extra packages including rasterVis, rgl and sp, at which point you can simply enter plot3D(Map1). Another application opens to display the 3d plot.

although I am still struggling to figure out how to save an image of the output!

now I'm starting to try and figure out how to compare movement across simulations, i.e. compare the distribution and density of movements between different rasters... I found a very useful website that is helping with this

http://evansmurphy.wix.com/evansspatial#!raster-analysis-in-r/c1n3l

so I'm hoping I should have something more solid to present in my last thesis chapter than a subjective description of movement... fingers crossed.



No comments:

Post a Comment