Created
October 24, 2012 18:41
-
-
Save AmeliaMN/3947988 to your computer and use it in GitHub Desktop.
Spatial analysis of Barnes and Noble bookstores in CA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Packages | |
library(fields) | |
library(sm) | |
library(spatstat) | |
library(splancs) | |
library(spatial) | |
library(geoR) | |
library(maps) | |
library(maptools) | |
#Getting the data going | |
data1 <- read.csv("barnesnoble.csv", header=F) | |
data1 <- data1[1:120,] | |
lat <- data1$V1 | |
lon <- data1$V2 | |
#Preparing the image grid | |
howmuch <- .5 | |
latrange <- 9 | |
lonrange <- 7 | |
irange <- (1/howmuch)*lonrange | |
jrange <- (1/howmuch)*latrange | |
x1 = matrix(0,nrow=irange,ncol=jrange) | |
for(i in 1:irange){ | |
for(j in 1:jrange){ | |
x1[i,j] = sum((lon < (floor(range(lon)[1]) + howmuch*i)) & (lon > (floor(range(lon)[1])-howmuch + howmuch*i -.001)) & | |
(lat < (floor(range(lat)[1]) +howmuch + howmuch*j)) & (lat > (floor(range(lat)[1]) + howmuch*j - .001))) | |
} | |
} | |
#Plotting | |
image(seq(from=-123, to=-116, by=howmuch), seq(from=32.5, to=41.5, by=howmuch), x1, col=gray((64:20)/64), axes=F, xlab="", ylab="") | |
xrange <- c(-124, -116) | |
yrange <- c(32, 42) | |
map("county", c("california"), xlim=xrange, ylim=yrange, add=T) | |
map.axes() | |
points(lon, lat, xlim=xrange, ylim=yrange, cex=0.5, pch=19, col="blue") | |
title(xlab="Longitude", ylab="Latitude", main="Locations of Barnes and Noble bookstores") | |
zmin = min(x1) | |
zmax = max(x1) | |
zmid = (zmin+zmax)/2 | |
z1 = (zmin + zmid)/2 | |
z2 = (zmid + zmax)/2 | |
legend("topright", title="Legend", as.character(c(zmax,z2,zmid,z1,zmin)),fill=gray(c(20,31,42,53,64)/64), bg="white") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment