Script for Module 3: Part 1
Script for Plot 1, a plot of petal length vs petal width. This is a basic X,Y plot:
plot(iris$Petal.Length, iris$Petal.Width,
xlab = "Petal Length (cm)", ylab = "Petal Width (cm)",
main = "Plot 1: Petal Length vs Petal Width",
pch = 7, col = "magenta")
legend("topleft", pch = 7, legend = "Iris Species'", col = 'Magenta',ncol = 4, title = "Legend")

Script for Plot 2, a plot that is focused on the petal length vs petal width for the species setosa. This plot required a subset of the original iris data in order to only plot the setosa species, also on this plot I applied limits to the X and Y to zoom the plot as the original was too large:
str(iris)
## 'data.frame': 150 obs. of 5 variables:
## $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
species_setosa = subset(iris, Species == "setosa") ##This is to pull out only the setosa species
str(species_setosa) ## View the structure of setosa and make sure everything looks right
## 'data.frame': 50 obs. of 5 variables:
## $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
plot(species_setosa$Petal.Length, species_setosa$Petal.Width,
xlab = "Petal Length (cm)", ylab = "Petal Width (cm)",
main = "Plot 2: Petal Length vs Petal Width for Setosa",
pch = 9, col = "cyan",
xlim = c(0,2), ylim = c(0,1)) ## Limits applied to zoom in on the data since default was too large
legend("topleft", pch = 9, legend = "Setosa'", col = 'Cyan',ncol = 4, title = "Legend")

Script for Plot 3, a plot of petal length vs petal width with a unique symbol for each species. Here the symbol (pch) was modified in order to apply a unique symbol to each point by using the species label from the iris dataset:
iris$Species
## [1] setosa setosa setosa setosa setosa setosa
## [7] setosa setosa setosa setosa setosa setosa
## [13] setosa setosa setosa setosa setosa setosa
## [19] setosa setosa setosa setosa setosa setosa
## [25] setosa setosa setosa setosa setosa setosa
## [31] setosa setosa setosa setosa setosa setosa
## [37] setosa setosa setosa setosa setosa setosa
## [43] setosa setosa setosa setosa setosa setosa
## [49] setosa setosa versicolor versicolor versicolor versicolor
## [55] versicolor versicolor versicolor versicolor versicolor versicolor
## [61] versicolor versicolor versicolor versicolor versicolor versicolor
## [67] versicolor versicolor versicolor versicolor versicolor versicolor
## [73] versicolor versicolor versicolor versicolor versicolor versicolor
## [79] versicolor versicolor versicolor versicolor versicolor versicolor
## [85] versicolor versicolor versicolor versicolor versicolor versicolor
## [91] versicolor versicolor versicolor versicolor versicolor versicolor
## [97] versicolor versicolor versicolor versicolor virginica virginica
## [103] virginica virginica virginica virginica virginica virginica
## [109] virginica virginica virginica virginica virginica virginica
## [115] virginica virginica virginica virginica virginica virginica
## [121] virginica virginica virginica virginica virginica virginica
## [127] virginica virginica virginica virginica virginica virginica
## [133] virginica virginica virginica virginica virginica virginica
## [139] virginica virginica virginica virginica virginica virginica
## [145] virginica virginica virginica virginica virginica virginica
## Levels: setosa versicolor virginica
head(iris$Species)
## [1] setosa setosa setosa setosa setosa setosa
## Levels: setosa versicolor virginica
levels(iris$Species)
## [1] "setosa" "versicolor" "virginica"
plot(iris$Petal.Length, iris$Petal.Width,
xlab = "petal length (cm)", ylab = "petal width (cm)",
main = "Plot 3: Petal Length vs Petal With by Species",
pch = c(1,4,9)[as.factor(iris$Species)]) ## Changes symbol by species type
legend("bottomright", pch = c(1,4,9), legend = levels(iris$Species), ncol = 4, title = "Species")

Script for Plot 4, a plot of petal length vs petal width with a unique color for each species. This plot required a change of color for each species so the color (col) is modified to apply a different color by the species similar to changing the symbol in the previous plot:
plot(iris$Petal.Length, iris$Petal.Width,
xlab = "Petal Length (cm)", ylab = "Petal Width (cm)",
main = "Plot 4: Petal Length vs Petal Width Color by Species",
pch = 13, col = c("orange", "cyan" ,"magenta")[as.factor(iris$Species)]) ## Here is where colors are changed by species
legend("bottomright", pch = 13, col = c("orange", "cyan" ,"magenta")
,legend = levels(iris$Species), ncol = 4, title = "Species")

Script for Plot 5, a plot of petal length vs petal width with symbol sized scaled by value of septal width and colored by species. This plot introduces the cex which allows the plot to change the symbol size by that attribute which was sepal width for this plot. I divided the sepal width by 2 in order to decrease the size of the symbols to allow them to be easier to view, otherwise they are too large to distinguish:
plot(iris$Petal.Length, iris$Petal.Width,
xlab = "Petal Length (cm)",
ylab = "Petal Width (cm)",
main = "Plot 5: Petal Length vs Petal Width by Sepal Width and Color",
pch = 11, cex = iris$Sepal.Width/2, col = c("blue", "darkorange" ,"purple")[as.factor(iris$Species)])
## cex changes the size of symbol by the sepal width value
legend("bottomright", pch = 13, col = c("blue", "darkorange" ,"purple")
,legend = levels(iris$Species), ncol = 4, title = "Species with size by Sepal Width")

Script for Plot 6, a plot of petal length vs petal width with a smoothing line applied. This plot returns to a plot similar to the first of a baisc X,Y plot; however by applying the command of scatter.smooth a smoothing line is applied to the plot:
scatter.smooth(iris$Petal.Length, iris$Petal.Width, ## Scatter smooth applies a smoothing line across the plot
xlab = "Petal Length (cm)", ylab = "Petal Width (cm)",
main = "Plot 6: Petal Length vs Petal Width with Smoothing Line",
pch = 9, col = "red")
legend("bottomright", pch = 9, legend = "Iris Species'", col = 'Red',ncol = 4, title = "Legend")
