Problem 1 [20 points]

Create a plotly graph of your choosing that represents at least two variables, one of which must be a categorical variable.

This plot can be a scatter plot, overlayed density plots (graphing variable is continuous, separate densities grouped by categorical variable), etc. choropleth maps could also be on the list…you have to admit they look kinda cool.

You can use any data of your choosing, just reference this.

The graph must include:

  1. customized hover text that is informative to the graphing elements in the plot

  2. separate color to represent groups

  3. labeled axes and appropriate title

Include at least a 1-paragraph discussion about the graph. Discuss what is being plotted and what information is being displayed in the graph. Discuss any information that the reader may gain from hovering the cursor over graphing elements. Discuss any issues/chalenges you had (if any) while making the plot, and you you dealt with or overcame them.

## Problem 1

library(plotly)
## Loading required package: ggplot2
## 
## 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
plot_ly(data = iris, x = ~Sepal.Length, y = ~Sepal.Width, 
        color = ~Species, type = 'scatter', mode = 'markers', 
        text = ~paste("Species: ", Species, "<br>",
                      "Sepal Length: ", Sepal.Length, "<br>",
                      "Sepal Width: ", Sepal.Width)) %>%
  layout(title = "Sepal Length vs Sepal Width by Species",
         xaxis = list(title = "Sepal Length"),
         yaxis = list(title = "Sepal Width"))
# Discussion
# The graph shows the relationship between sepal length and sepal width of iris flowers, with each point representing an individual observation from the iris data set. The points are colored based on the species of the iris, allowing for easy identification of different species clusters. The hover text provides additional information, including the species of the iris, its sepal length, and its sepal width. This allows the reader to gain insight into specific data points so they can see exactly what each point represents.

Problem 2 [20 points]

Create an animated plotly graph with a data set of your choosing. This can be, but does not have to be a scatter plot. Also, the animation does not have to take place over time. As mentioned in the notes, the frame can be set to a categorical variable. However, the categories the frames cycle through should be organized (if needs be) such that the progression through them shows some pattern.

This graph should include:

  1. Aside from the graphing variable, a separate categorical variable. For example, in our animated scatter plot we color grouped the points by continent.

  2. Appropriate axis labels and a title

  3. Augment the frame label to make it more visible. This can include changing the font size and color to make it stand out more, and/or moving the frame label to a new location in the plotting region. Note, if you do this, make sure it is till clearly visible and does not obstruct the view of your plot.

Include at least a 1-paragraph discussion about the plot. Discuss what you are plotting and what trends can be seen throughout the animation. Discuss any issues, if any, you ran into in making the plot and how you overcame them.

## Problem 2

library(plotly)

plot_ly(data = iris, x = ~Sepal.Length, y = ~Sepal.Width, 
                         color = ~Species, type = "scatter", mode = "markers",
                         frame = ~Species) %>%
  layout(title = "Animated Scatter Plot of Sepal Length vs Sepal Width",
         xaxis = list(title = "Sepal Length"),
         yaxis = list(title = "Sepal Width"),
         showlegend = TRUE,
         scene = list(
           xaxis = list(title = "Sepal Length"),
           yaxis = list(title = "Sepal Width"),
           zaxis = list(title = "Petal Length")
         ),
         font = list(size = 16, color = "black"))
# Discussion
#The animated scatter plot shows the relationship between Sepal Length and Sepal Width of iris flowers, with each species represented by a different color. As the animation progresses, we can see how the points shift across the plot space, indicating how the Sepal Length and Width vary across the different species of iris. Setosa tends to have shorter sepals compared to Versicolor and Virginica. There might be variations in the spread and distribution of data points within each species, showing insights into the variability of sepal dimensions within each iris species.

What to turn in: