library(plotly)
library(dslabs)
library(ggplot2)
library(tidyverse)
##### Problem 1


life_exp2010 <- gapminder %>%
  filter(year == "2010")
plot_ly(life_exp2010, x=~population, y = ~life_expectancy, color = ~continent,
        hoverinfo = "text",
        type = "scatter",
        mode = "markers",
        text = ~country)%>%
        layout(title = "2010 Life Expectancy",
               xaxis = list(type = "log"))
##### I chose the data from the gapminder data and filtered for life expectancy for 2010 compared to the population.
##### I have also grouped the countries by continent which if hovered over the marker, you can see each individual country.
##### I have also scaled the x axis appropriately so the markers are legible to the audiance.
##### Problem 2

Problem2 <- gapminder %>%
  plot_ly(x = ~gdp, y = ~infant_mortality, 
          hoverinfo = "text", 
          text = ~country) %>%
add_markers (frame = gapminder$year, 
             ids = ~country,
             size = ~population, 
             color=~continent,
             marker = list(sizemode = "diameter"))%>%
  layout(title = "Infant Mortality Rate Compared To GDP",  xaxis = list(type = "log"))

Problem2 %>%
  animation_slider(currentvalue = list(prefix = "Year"),
                   font = list(color = "blue",
                               size = 25))
##### The data that I chose to graph was the infant mortality rate, compared to the country GDP.
##### The infant mortality rate throughout the world is a very important topic and especially in developing countries
##### This is true in this graph.  The higher mortality rates for infants were in less economic fluent countries.
##### While this might not be surprising, the positive about this data that is the mortality rate does drop as a whole for
##### every country as time goes on.  This would lead to the assumption that research, advancement in medicine, and awareness
##### made a positive impact.