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.

This plot visualizes the relationship between sepal length and petal length in the Iris dataset using a scatter plot with separate colors for each species. The plot shows that there is a strong positive correlation between sepal length and petal length, which is consistent across all three species. However, the different species can be distinguished by their average sepal and petal lengths, with the setosa species having the shortest and widest petals, and the versicolor and virginica species having longer and narrower petals. This information is displayed in the hover text, which includes the sepal and petal widths for each point. Overall, this plot provides a clear and intuitive way to visualize the relationship between two continuous variables in the presence of a categorical variable.

#Loading plotly
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
#Loading iris data set
df <- iris

#Creating scatter plot
fig <- plot_ly(data = df, x = ~Sepal.Length, y = ~Petal.Length, 
               color = ~Species, type = "scatter", mode = "markers",
               hovertemplate = paste("Sepal Width: %{Sepal.Width}<br>",
                                     "Petal Width: %{Petal.Width}<br>"))
#Labeling scatter plot
fig <- fig %>% layout(title = "Relationship between Sepal Length and Petal Length",
                      xaxis = list(title = "Sepal Length"),
                      yaxis = list(title = "Petal Length"))

#Displaying scatter plot
fig

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.

The animated Plotly graph was generated in R with the “gapminder” dataset, which illustrates the correlation between life expectancy and GDP per capita by continent over time. The paragraph observes that the graph exhibits a positive relationship between the two variables, with most countries experiencing a steady increase in both measures over time. Furthermore, the paragraph points out the continent-specific variations in life expectancy and GDP per capita, highlighting lower values for Africa and higher values for Europe and North America. Lastly, the animation adds a dynamic and engaging element to the visualization of the correlation between the variables over time.

#Loading gapminder and plotly
library(gapminder)
## Warning: package 'gapminder' was built under R version 4.2.3
library(plotly)

#Creating an animated scatter plot
p <- plot_ly(gapminder, x = ~gdpPercap, y = ~lifeExp, color = ~continent,
             size = ~pop, frame = ~year, type = "scatter", mode = "markers") %>%
  layout(xaxis = list(title = "GDP per capita"), yaxis = list(title = "Life expectancy"),
         title = "Relationship between life expectancy and GDP per capita by continent",
         showlegend = TRUE, legend = list(x = 0, y = 1))

#Customizing the frame label
p %>% animation_opts(frame = 150, easing = "linear") %>%
  animation_slider(currentvalue = list(font = list(size = 16, color = "red")),
                   borderwidth = 3, bordercolor = "black")
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.

What to turn in: