library(reshape)  #loads the reshape package for changing the data format

# "melt' the MOtest data using "reshape" package then cast it in the correct format
MO2<-melt(MOtest, id=c("route", "stop", "SiteID", "ENTERED.BY", "BUFFER.SIZE"))
MO3<-cast(MO2, route + stop + SiteID + ENTERED.BY ~ variable + BUFFER.SIZE)
#convert the resulting array to a data frame called MOland
MOland<-as.data.frame(MO3)

#look at correlations among all the various landscape variables.
MOcordata<-MOland[5:49]  #pulls out just the numerical variables to create a correlation matrix
MOcors<-cor(MOcordata, use="pairwise.complete.obs") #correlations of all variables

#example for correlations between two variables at a time
attach(MOland)
cor(PROP_DEV_300, PROP_DEV_1000, use="pairwise.complete.obs")

#merges the landscape data with the call summary data to create MOcombined
MOcombined<-merge(MOland, summaryMO, by ="SiteID")

attach(MOcombined)  #tells R that anything without a data statement refers to this dataset
plot(T_ROAD_LEN_1000, PROP_DEV_1000) #sample scatterplot

#look at effects of survey effort on recorded species richness
plot(Num.Surveys, richness)
cor(Num.Surveys, richness, use="pairwise.complete.obs")

#might want to drop fewer than 8 surveys
MOcomb8<-subset(MOcombined, Num.Surveys>7)
attach(MOcomb8)
cor(Num.Surveys, richness, use="pairwise.complete.obs")

#make a plot with a regression line
plot(PROP_FOR_1000~PROP_AGR_1000)
abline(lm(PROP_FOR_1000~PROP_AGR_1000))

# example for how to do a histogram
hist (WET_AREA_300)
