Question 1.

selected_species <- iris[iris$Species == "setosa",]

Question 2.

summary(selected_species$Petal.Length)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   1.400   1.500   1.462   1.575   1.900
#range calculations - petal length
range(selected_species$Petal.Length)
## [1] 1.0 1.9
#mean calculation - petal length
mean(selected_species$Petal.Length)
## [1] 1.462
#SD calc - petal length
sd(selected_species$Petal.Length)
## [1] 0.173664
#varience calc - petal length
var(selected_species$Petal.Length)
## [1] 0.03015918
#Sepal
summary(selected_species$Sepal.Length)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   4.300   4.800   5.000   5.006   5.200   5.800
#range calculations - sepal length
range(selected_species$Sepal.Length)
## [1] 4.3 5.8
#mean calculation - sepal length
mean(selected_species$Sepal.Length)
## [1] 5.006
#SD calc - sepal length
sd(selected_species$Sepal.Length)
## [1] 0.3524897
#varience calc - sepal length
var(selected_species$Sepal.Length)
## [1] 0.124249
#Histogramn - Petal length
hist(selected_species$Petal.Length,
     main = "Plants with differing Iris setosa petal length (cm)",
     xlab = "petal length (cm)",
     ylab = "count",
     col = "plum")

#histogram - sepal 
hist(selected_species$Sepal.Length,
     main = "Plants with differing Iris Setosa sepal length (cm)",
     xlab = "sepal length (cm)",
     ylab = "count",
     col = "olivedrab")

#making an x-y plot
plot(selected_species$Petal.Length,
     selected_species$Petal.Width,
     main = "Petal length vs Petal width (Iris setosa",
     xlab = "Petal length (cm)",
     ylab = "Petal width (cm)",
     pch = 20,
     col = "plum")

#Correlation calc
cor.test(selected_species$Petal.Length,
         selected_species$Petal.Width)
## 
##  Pearson's product-moment correlation
## 
## data:  selected_species$Petal.Length and selected_species$Petal.Width
## t = 2.4354, df = 48, p-value = 0.01864
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.05870091 0.55842995
## sample estimates:
##     cor 
## 0.33163
plot(selected_species$Sepal.Length,
     selected_species$Sepal.Width,
     main = "Sepal length vs Sepal width (Iris setosa",
     xlab = "Sepal length (cm)",
     ylab = "Sepal width (cm)",
     pch = 20,
     col = "olivedrab")

cor.test(selected_species$Sepal.Length,
         selected_species$Sepal.Width)
## 
##  Pearson's product-moment correlation
## 
## data:  selected_species$Sepal.Length and selected_species$Sepal.Width
## t = 7.6807, df = 48, p-value = 6.71e-10
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.5851391 0.8460314
## sample estimates:
##       cor 
## 0.7425467
mean_setosa <- mean(iris$Petal.Length[iris$Species == "setosa"])
mean_versicolor <- mean(iris$Petal.Length[iris$Species == "versicolor"])
mean_virginica <- mean(iris$Petal.Length[iris$Species == "virginica"])

mean_petal <- c(mean_setosa,
                mean_versicolor,
                mean_virginica)
names(mean_petal) <- c("setosa",
                       "versicolor",
                       "virginica")
mean_petal
##     setosa versicolor  virginica 
##      1.462      4.260      5.552
#S.E
se_setosa <- sd(iris$Petal.Length[iris$Species == "setosa"]) /
              sqrt(length(iris$Petal.Length[iris$Species == "setosa"]))
se_versicolor <- sd(iris$Petal.Length[iris$Species == "versicolor"]) /
                sqrt(length(iris$Petal.Length[iris$Species == "versicolor"]))
se_virginica <- sd(iris$Petal.Length[iris$Species == "virginica"]) /
                sqrt(length(iris$Petal.Length[iris$Species == "virginica"]))
se_petal <- c(se_setosa,
              se_versicolor,
              se_virginica)
names(se_petal) <- c("setosa",
                     "versicolor",
                     "virginica")
se_petal
##     setosa versicolor  virginica 
## 0.02455980 0.06645545 0.07804970
#barplot
bp <- barplot(mean_petal,
              ylim = c(0, max(mean_petal + se_petal) + 1),
              col = c("plum", "lightblue", "lightgreen"),
              ylab = "Mean Petal Length (cm)",
              main = "Mean Petal Length by Species")
#error bars
arrows(bp,
       mean_petal - se_petal,
       bp,
       mean_petal + se_petal,
       angle = 90,
       code = 3, #caps
       length = 0.1) #caps