This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
##Input Data for Each of 7 Columns of Data:
Island=c("Santa Barbara","Anacapa","San Miguel","San Nicolas","San Clemente","Santa Catalina","Santa Rosa","Santa Cruz")
Area=c(2.6, 2.9, 37, 58, 145, 194, 217, 294)
Dist=c(61, 20, 42, 98, 79, 32, 44, 30)
Native=c(88,190,198,139,272,421,387,480)
Endemic=c(14,22,18,18,47,37,42,45)
Exotic=c(44,75,69,131,110,185,98,170)
Total=c(132,265,267,270,382,604,484,650)
##Coerce Data Vectors Into a Dataframe:
ChannelIslands=data.frame(Island, Area, Dist, Native, Endemic, Exotic, Total)
##Remove individual files now that they are assembled into a dataframe.
rm(Island, Area, Dist, Native, Endemic, Exotic, Total)
##Convert “Island” (the variable containing island names) into a Factor Variable:
ChannelIslands$Island <- factor(ChannelIslands$Island)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.5.2
library(plotly)
## Warning: package 'plotly' was built under R version 4.5.2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
ggplot(ChannelIslands, aes(x = Area, y = Total)) +
geom_point(aes(color = Area, size = Area)) +
geom_smooth(method = "lm", se = TRUE, color = "black") +
xlab("Island Area (km²)") +
ylab("Total Plant Species Richness") +
ggtitle("Total Plant Species Richness vs. Island Area (Channel Islands)")
## `geom_smooth()` using formula = 'y ~ x'
m_native <- lm(Native ~ Area, data = ChannelIslands)
summary(m_native)
##
## Call:
## lm(formula = Native ~ Area, data = ChannelIslands)
##
## Residuals:
## Min 1Q Median 3Q Max
## -57.612 -34.226 -7.542 34.551 61.581
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 124.8303 25.9310 4.814 0.002958 **
## Area 1.2376 0.1653 7.488 0.000293 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 47.9 on 6 degrees of freedom
## Multiple R-squared: 0.9033, Adjusted R-squared: 0.8872
## F-statistic: 56.07 on 1 and 6 DF, p-value: 0.0002931
ggplot(ChannelIslands)+
geom_point(aes(x = Area, y = Native),
color = "forestgreen", shape = 15, size = 2.5) +
geom_smooth(aes(x = Area, y = Native),
color = "forestgreen", se = FALSE) +
geom_point(aes(x = Area, y = Endemic),
color = "dodgerblue", shape = 16, size = 2.5) +
geom_smooth(aes(x = Area, y = Endemic),
color = "dodgerblue", se = FALSE) +
geom_point(aes(x = Area, y = Exotic),
color = "firebrick1", shape = 17, size = 2.5) +
geom_smooth(aes(x = Area, y = Exotic),
color = "firebrick1", se = FALSE) +
xlab("Island Area (km)") +
ylab("Species Richness") +
ggtitle("Area for Native, Endemic, and Exotic Plants") +
theme_gray()
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
res_df <- data.frame(
Island = ChannelIslands$Island,
Distance = ChannelIslands$Dist,
Residuals = m_native$residuals)
ggplot(res_df, aes(x = Distance, y = Residuals)) +
geom_point(size = 3) +
geom_smooth(se = FALSE) +
xlab("Distance from Mainland (km)") +
ylab("Residual Native Richness") +
ggtitle("Residuals from Native ~ Area vs. Distance")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
m_resid_dist <- lm(Residuals ~ Distance, data = res_df)
summary(m_resid_dist)
##
## Call:
## lm(formula = Residuals ~ Distance, data = res_df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -37.849 -18.320 8.098 15.904 29.724
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 71.3151 20.4815 3.482 0.01311 *
## Distance -1.4052 0.3621 -3.880 0.00817 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 25.57 on 6 degrees of freedom
## Multiple R-squared: 0.7151, Adjusted R-squared: 0.6676
## F-statistic: 15.06 on 1 and 6 DF, p-value: 0.008167