Task 1: Reflection

I missed the in-class portion for this so I went through 1_InteractivwPlots.R and Interactivity_INTRO.R. First of all I’ll talk about my opinions with using ggplot for interactive graphs: its really intuitive. The one thing that threw me off, however, was the use of mapping. Also its interesting how I can still use theme_minimal and other ggplot features for interactive graphs. Now when it comes to the actual d ata its interesting how we can see the percent of women in parliment compared to men, a result i didnt actually expect (i expected a more equal comparison)

Task 2

library(tidyverse)
library(plotly)

library(WDI)

# lets use wdi to get gdp per capita
wdi_data <- WDI(
  country = "all",
  indicator = c("NY.GDP.PCAP.CD", "SP.POP.TOTL"),
  start = 2000,
  end = 2022,  # Added missing closing parenthesis
)

Do the following:

  1. Make a plot. Any kind of plot will do (though it might be easiest to work with geom_point()).

  2. Make the plot interactive with ggplotly().

  3. Make sure the hovering tooltip is more informative than the default.

Good luck and have fun!

wdi_clean <- wdi_data %>%
  drop_na() %>%
  rename(
    gdp_per_capita = NY.GDP.PCAP.CD,
    population = SP.POP.TOTL
  )

# lets create a base ggplot but a few interesting things
# first of all mak eit log scale or else the data aint visible
# next ensure to use paste as were gonna make it multiline, puttit in one str doesnt work
# finally we gotta call labs idk why but it woouldnt wrork without i
p <- ggplot(wdi_clean, aes(x = gdp_per_capita, y = population)) +
  geom_point(aes(
    text = paste(
      "Country:", country,
      "\nGDP per capita: $", round(gdp_per_capita, 2),
      "\nPopulation:", format(population, big.mark=","),
      "\nYear:", year
    )
  )) +
  scale_y_log10() +
  scale_x_log10() +
  labs(
    title = "GDP per Capita vs Population by Country",
    x = "GDP per Capita (USD)",
    y = "Population"
  )
## Warning in geom_point(aes(text = paste("Country:", country, "\nGDP per capita:
## $", : Ignoring unknown aesthetics: text
# lastly invoke it
ggplotly(p, tooltip = "text")

Task 3:

Install the {flexdashboard} package and create a new R Markdown file in your project by going to File > New File… > R Markdown… > From Template > Flexdashboard.

Using the documentation for {flexdashboard} online, create a basic dashboard that shows a plot (static or interactive) in at least three chart areas. Play with the layout if you’re feeling brave.