Just when I thought it wouldn’t get any better, Interactive graph comes in to prove me wrong. This chapter has been the most exciting yet and most challenging as well. I have been a fun of interactive plot with it’s ability to engage readers and provide a wide range of information at a go. I have wondered how it was done and assumed it takes the most sophisticated artificial intelligence to get it done.I am by no means suggesting it is easy, but certainly easier than i thought.
Going through the resources posted on the course page makes me feel that I am only scratching the surface of interactive graph making, but one that I am excited about and looking forward to learn more. I wanted to see how I could make the graph I made from the “Annotation” chapter interactive. I realized I had to readjust some of the annotations I had made as the flexdashboard omitted them upon knitting.
This is certainly something I will spend much time on, even after the semester, to get a good knowledge.
library(tidyverse)
library(plotly)
library(dplyr)
wdi_raw <- read_csv("data/wdi_raw.csv")
wdi_clean <- wdi_raw %>%
filter(region != "Aggregates") %>%
filter(region == "Sub-Saharan Africa") %>%
filter(year == 2015) %>%
rename(life_expectancy = SP.DYN.LE00.IN,
gdp_per_cap = NY.GDP.PCAP.KD) %>%
drop_na(gdp_per_cap) %>%
select(iso3c, country, year, region, income,life_expectancy, gdp_per_cap) %>%
mutate( gdp_per_cap = round(gdp_per_cap),
life_expectancy = round(life_expectancy))
gdp_life_exp_cor <- ggplot(wdi_clean,
aes(x = gdp_per_cap, y = life_expectancy, color = income)) +
geom_point(aes(fiifi = country, naana = gdp_per_cap,
efua = life_expectancy, ayeyi = income)) +
geom_smooth(method = "lm") +
labs(x = "GDP Per Capita", y = "Life Expectancy",
title = "Relationship between life expectancy and GDP per capita",
caption = "Source: The World Bank.\nSub-Sahara African countries") +
theme(plot.title = element_text(hjust = 1),
legend.position = "bottom") +
theme_minimal()
gdp_life_exp_cor
ggplotly(gdp_life_exp_cor, tooltip = c("fiifi", "efua","naana","ayeyi"))
Access Google Sheets using the Sheets API V4 • googlesheets4. (n.d.). Retrieved October 30, 2023, from https://googlesheets4.tidyverse.org/#auth
Data Visualization with R - Interactivity. (n.d.). Data Visualization with R. Retrieved October 30, 2023, from https://datavizf23.classes.andrewheiss.com/content/10-content.html
Grolemund, Y. X., J. J. Allaire, Garrett. (n.d.). 5.2 Components | R Markdown: The Definitive Guide. Retrieved October 30, 2023, from https://bookdown.org/yihui/rmarkdown/dashboard-components.html
R Markdown Format for Flexible Dashboards • flexdashboard. (n.d.). Retrieved October 30, 2023, from https://pkgs.rstudio.com/flexdashboard/
Using shiny with flexdashboard • flexdashboard. (n.d.). Retrieved October 30, 2023, from https://pkgs.rstudio.com/flexdashboard/articles/shiny.html