My map

I made a map of where different Potentilla species have been recorded on MPG ranch.This is a nice visual because previous research has found a negative soil feedback between the native (P.glandulosa and P.gracilis) and the invasive (P.recta), where the invasive was found to be less competitive when grown near its native relative. In this map I see P. recta hanging out on its own mostly.

library(ggmap)
## Warning: package 'ggmap' was built under R version 3.2.5
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.2.5
library(ggplot2)
mpg<- c(lon = -114.0048532,lat = 46.6856164)
myMPG <- get_map(location=mpg,source="stamen", maptype="terrain", crop=FALSE, zoom=13)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=46.685616,-114.004853&zoom=13&size=640x640&scale=2&maptype=terrain&sensor=false
## Map from URL : http://tile.stamen.com/terrain/13/1500/2890.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1501/2890.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1502/2890.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1503/2890.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1500/2891.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1501/2891.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1502/2891.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1503/2891.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1500/2892.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1501/2892.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1502/2892.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1503/2892.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1500/2893.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1501/2893.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1502/2893.jpg
## Map from URL : http://tile.stamen.com/terrain/13/1503/2893.jpg
ggmap(myMPG)

potcom=read.csv("potcom.csv",header = TRUE)
ggmap(myMPG)+
geom_point(aes(x =long, y =lat, show_guide=T,colour=type), data = potcom,
 alpha = .5, na.rm = T, size = 3) +
scale_colour_brewer(potcom$type,type="qual",palette="Dark2",direction = 1) +
xlab("Longitude") +
ylab("Latitdude") +
ggtitle("Potentilla Map")

Muese Variogram

Here I plotted the variogram for the lead concentrations in the Muese river. Similar to cadmium, it shows spatial autocorrelation to about a kilometer maybe a bit more, right about 1.25km. Cloud= TRUE means that it will plot all the data points squared distance, cloud=FALSE will only plot an average gamma at a single distance.

library(sp)
## Warning: package 'sp' was built under R version 3.2.5
data(meuse)
head(meuse)
##        x      y cadmium copper lead zinc  elev       dist   om ffreq soil
## 1 181072 333611    11.7     85  299 1022 7.909 0.00135803 13.6     1    1
## 2 181025 333558     8.6     81  277 1141 6.983 0.01222430 14.0     1    1
## 3 181165 333537     6.5     68  199  640 7.800 0.10302900 13.0     1    1
## 4 181298 333484     2.6     81  116  257 7.655 0.19009400  8.0     1    2
## 5 181307 333330     2.8     48  117  269 7.480 0.27709000  8.7     1    2
## 6 181390 333260     3.0     61  137  281 7.791 0.36406700  7.8     1    2
##   lime landuse dist.m
## 1    1      Ah     50
## 2    1      Ah     30
## 3    1      Ah    150
## 4    0      Ga    270
## 5    0      Ah    380
## 6    0      Ga    470
coordinates(meuse) <- ~x+y
proj4string(meuse) <- CRS("+init=epsg:28992")
class(meuse)
## [1] "SpatialPointsDataFrame"
## attr(,"package")
## [1] "sp"
bubble(meuse, xcol="x",ycol="y",zcol="lead", maxsize = 2.5, main = "Lead concentrations (ppm)")

library(gstat)
## Warning: package 'gstat' was built under R version 3.2.5
leadVarCloud <- variogram(lead~1, meuse, cloud = TRUE)
leadVar <- variogram(lead~1, meuse, cloud = FALSE)

plot(leadVarCloud,pch=20,cex=1.5,col="navy",
       ylab=expression("Semivariance ("*gamma*")"),
       xlab="Distance (m)",main = "Lead concentrations (ppm)")

plot(leadVar,pch=20,cex=1.5,col="black",
     ylab=expression("Semivariance ("*gamma*")"),
     xlab="Distance (m)", main = "Lead concentrations (ppm)")

Experimentation

plot(variogram(log(lead)~1, meuse),cloud=FALSE,main="Log transform")

The distance and pattern of the plot stay the same, but the gamma values (squared distances) are much smaller.

plot(variogram(log(lead)~1, meuse,cutoff=750), main="Cutoff = 750")

I think this is not too different when all the distances were compared.

plot(variogram(log(lead)~1, meuse,cutoff=250), main="Cutoff = 250")

This one looks much different when we limit our comparison distance. Lead concentrations 50 meters apart are very similar, and there is not plateau, as we already know.

Mystery set

load("E:/spring16/mysteryData.Rdata")
data(dat)
## Warning in data(dat): data set 'dat' not found
coordinates(dat) <- ~x+y
class(dat)
## [1] "SpatialPointsDataFrame"
## attr(,"package")
## [1] "sp"
bubble(dat, xcol="x",ycol="y",zcol="z", maxsize = 2.5, main = "Chocolate chip cookies consumed per capita")

#There are large differences between the data values, I may log transform therse data.
plot(variogram(z~1, dat), main="Normal")

plot(variogram(log(z)~1, dat), main="Log transform")

plot(variogram(z~1, dat, cutoff=10), main="Cutoff = 10")

The data semivariance does not plateau.

My work part 2

First I made a clumped distribution of points and that was confirmed by the observed K line being above the K high and low intervals. The uniform distribution was next and we can see this graphically by the observed line falling below the lower K boundary. The random distribution is made last and the observed line falls withing the high and low boundaries. I just have my code here becasue rmarkdown was not having the clickppp function

library(spatstat)
## Warning: package 'spatstat' was built under R version 3.2.5
## Loading required package: nlme
## 
## spatstat 1.45-0       (nickname: 'One Lakh') 
## For an introduction to spatstat, type 'beginner'
## 
## Attaching package: 'spatstat'
## The following object is masked from 'package:gstat':
## 
##     idw

clump=clickppp(n=35) plot(density(clump)) points(clump,pch=20) clump.env <- envelope(clump, Kest, nsim = 100) op = par(mfrow=c(1,1)) plot(clump.env)

uniform <- clickppp(n = 35) plot(density(uniform)) points(uniform,pch=20) uniform.env <- envelope(uniform, Kest, nsim = 100) plot(uniform.env)

CSR <- clickppp(n = 35) plot(density(CSR)) points(CSR,pch=20) CSR.env <- envelope(CSR, Kest, nsim = 100) plot(CSR.env)

Not trees, but a fun-gal friend

data("sporophores")
str(sporophores)
## List of 6
##  $ window    :List of 5
##   ..$ type  : chr "polygonal"
##   ..$ xrange: num [1:2] -145 145
##   ..$ yrange: num [1:2] -145 145
##   ..$ bdry  :List of 1
##   .. ..$ :List of 2
##   .. .. ..$ x: num [1:128] 145 145 144 143 142 ...
##   .. .. ..$ y: num [1:128] 0 7.11 14.21 21.28 28.29 ...
##   ..$ units :List of 3
##   .. ..$ singular  : chr "cm"
##   .. ..$ plural    : chr "cm"
##   .. ..$ multiplier: num 1
##   .. ..- attr(*, "class")= chr "units"
##   ..- attr(*, "class")= chr "owin"
##  $ n         : int 330
##  $ x         : num [1:330] -103.6 -103.4 -102.1 -99.6 -97.1 ...
##  $ y         : num [1:330] -3.03 -1.51 -2.78 -10.58 -11.35 ...
##  $ markformat: chr "vector"
##  $ marks     : Factor w/ 3 levels "L laccata","L pubescens",..: 1 1 1 1 1 1 1 1 1 1 ...
##  - attr(*, "class")= chr "ppp"
plot(sporophores, chars=c(16,1,2), cex=0.6)

l.laccata <- subset(sporophores, marks=="L laccata", drop=TRUE)
summary(l.laccata)
## Marked planar point pattern:  190 points
## Average intensity 0.002877678 points per square cm
## 
## Coordinates are given to 6 decimal places
## 
## Multitype:
##           frequency proportion   intensity
## L laccata       190          1 0.002877678
## 
## Window: polygonal boundary
## single connected closed polygon with 128 vertices
## enclosing rectangle: [-145, 145] x [-145, 145] cm
## Window area = 66025.5 square cm
## Unit of length: 1 cm
plot(l.laccata)##looks pretty clumped to me!

plot(envelope(l.laccata, Kest, nsim = 100))
## Generating 100 simulations of CSR  ...
## 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
## 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
## 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
## 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
## 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
## 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
## 91, 92, 93, 94, 95, 96, 97, 98, 99,  100.
## 
## Done.

The L.laccata seem to have a very clumped spatial distribution. Is the distance their spores can travel limited?

l.pubenscens <- subset(sporophores, marks=="L pubescens", drop=TRUE)
summary(l.pubenscens)
## Marked planar point pattern:  11 points
## Average intensity 0.0001666024 points per square cm
## 
## Coordinates are given to 6 decimal places
## 
## Multitype:
##             frequency proportion    intensity
## L pubescens        11          1 0.0001666024
## 
## Window: polygonal boundary
## single connected closed polygon with 128 vertices
## enclosing rectangle: [-145, 145] x [-145, 145] cm
## Window area = 66025.5 square cm
## Unit of length: 1 cm
plot(l.pubenscens)##looks pretty clumped to me!

plot(envelope(l.pubenscens, Kest, nsim = 100))
## Generating 100 simulations of CSR  ...
## 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
## 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
## 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
## 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
## 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
## 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
## 91, 92, 93, 94, 95, 96, 97, 98, 99,  100.
## 
## Done.

Again these fungi display a clumped distribution. The number of observations was very small and I think that contributed to the odd shape of the graph.

hebloma <- subset(sporophores, marks=="Hebloma spp", drop=TRUE)
summary(hebloma)
## Marked planar point pattern:  129 points
## Average intensity 0.001953792 points per square cm
## 
## Coordinates are given to 6 decimal places
## 
## Multitype:
##             frequency proportion   intensity
## Hebloma spp       129          1 0.001953792
## 
## Window: polygonal boundary
## single connected closed polygon with 128 vertices
## enclosing rectangle: [-145, 145] x [-145, 145] cm
## Window area = 66025.5 square cm
## Unit of length: 1 cm
plot(hebloma)##It is like a circle of clumps. 

plot(envelope(hebloma, Kest, nsim = 100))
## Generating 100 simulations of CSR  ...
## 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
## 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
## 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
## 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
## 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
## 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
## 91, 92, 93, 94, 95, 96, 97, 98, 99,  100.
## 
## Done.

Oh so clumped! These data were only recorded in an area less than one meter. It would be interesting to see the distribution at a larger scale. However I do think that at a larger distance we would still see a clumped distribution because sporocarps tend to be found near tree bases, I believe.