3.2 Correlation

The iris dataset contains measurements on 150 flowers of three different species.


Load the iris dataset.

data("iris")


View the iris dataset like a spreadsheet.

View(iris)


Use ggplot2 to create a scatter plot to compare the Petal.Length (x-axis) and Petal.Width (y-axis)

ggplot(iris, aes(x=Petal.Length, y=Petal.Width)) + geom_point()


Test for a correlation between Petal.Length and Petal.Width in the iris dataset, saving the result to a variable called ct

cor.test(iris$Petal.Length, iris$Petal.Width)


Extract the estimate of the correlation from your "ct" object

ct$estimate


Extract the p-value for correlation from your "ct" object

ct$p.value


Extract a 95% confidence interval for the correlation coefficient from your "ct" object

ct$conf.int