Quarto Document for Module 3

Author

Colleen Marcus

Exercise for Module 6

This Quarto document takes the code and plots from part 1 of the exercise from Module 3 and organizes it into a nice and neat Quarto document. A quick note, that I will not be using every single line of code and every plot from excercise 3, but just a few as to show some skills in Quarto formatting.

Module 3 Data

Let’s start by uploading the data we’ll need from Module 3 and creating some variables.

iris <- read.csv("iris.csv")
summary(iris)
  Sepal.Length    Sepal.Width     Petal.Length    Petal.Width   
 Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100  
 1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300  
 Median :5.800   Median :3.000   Median :4.350   Median :1.300  
 Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199  
 3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800  
 Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500  
      Species         Code  
 Length   :150   Min.   :1  
 N.unique :  3   1st Qu.:1  
 N.blank  :  0   Median :2  
 Min.nchar:  6   Mean   :2  
 Max.nchar: 10   3rd Qu.:3  
                 Max.   :3  

Plots

Now let’s use this data to make some plots. We’ll start with a simple plot of Petal Length (x) vs Petal Width (y)

plot(iris$Petal.Length, iris$Petal.Width, xlab = "Petal Length", 
     ylab = "Petal Width", main = "Petal Length vs Width")

And how about we do that same plot, but with different symbols for each species?

plot (iris$Petal.Length, iris$Petal.Width, xlab = "Petal Length", 
     ylab = "Petal Width", main = "Petal Length vs Width by Species",
     pch = c(15, 16, 17)[iris$Species])
legend("topleft", pch = c(15,16,17), legend = c("setosa", "versicolor", "virginica"))

Ahhh, but it looks like some of our data is maybe being read as a character instead of a factor, so let’s change that

iris$Species <- factor(iris$Species)

Now try re-running the code and see what the plot looks like.

That’s better :)

Okay, let’s do one more plot showing Petal Length (x) vs Petal Width (y) with different colors for the different species. And let’s be creative with the colors!

plot(iris$Petal.Length, iris$Petal.Width, xlab = "Petal Length", 
     ylab = "Petal Width", main = "Petal Length vs Width by Species",
     pch = 16, col = c("orange", "1", "6")[iris$Species])

And now let’s add a legend so we know what all the pretty colors mean

plot(iris$Petal.Length, iris$Petal.Width, xlab = "Petal Length", 
     ylab = "Petal Width", main = "Petal Length vs Width by Species",
     pch = 16, col = c("orange", "1", "6")[iris$Species])
legend("topleft", pch = 16, col = c("orange", "1", "6"), 
       legend = c("setosa", "versicolor", "virginica"))

Conclusion

Alright, well that’s all for now. Until our next R adventure!

You can also find a link to my RPubs page here.