I could see ggplotly being useful for more than just end users of the plots, it could be useful for exploratory data analysis and building out the plots. In the last assignment, I did a lot of sorting in the data browser to try to figure out where certain points were, based on where they were situated on the x and y axes. Using tooltips during the creation of the plot could make it easier to build a good plot AND would help build it in a way where the reader might be able to use tooltips in a similar way. I really liked the Explorable Explanations examples, and I could definitely see myself exploring these options for future projects.
I actually use dashboards a lot for my work, and I’m really interested to learn more about the ‘back end’ of them. Similar to static plots in a publication, they can also be used to show specifically what the author wants the reader to see. It might just be me, but I find I rarely use dashboards for the way they’re intended - I’m usually trying to understand a single data point or to track down source materials. I really like the idea of them, but it’s difficult to know what the target demographic is - are there really enough people who are checking dashboards regularly enough to know what the trends are? I’m sure there are, but the purpose of a specific dashboard is something I’ll keep in mind when I’m making them.
library(tidyverse)
library(plotly)
library(gapminder)
gapminder_raw <- gapminder
I really liked exploring the gapminder dataset, with a focus on different regions of Europe in the last assignment, so I think I’ll do it again!
gm_europe <- gapminder_raw %>%
filter(continent == "Europe") %>%
mutate(region = case_when(country %in% c("Albania", "Bosnia and Herzegovina", "Bulgaria", "Croatia", "Czech Republic", "Hungary", "Montenegro", "Poland", "Romania", "Serbia", "Slovak Republic", "Slovenia", "Turkey") ~ "Central and Eastern",
country %in% c("Denmark", "Finland", "Iceland", "Ireland", "Norway", "Sweden", "United Kingdom") ~ "Northern",
country %in% c("Greece", "Italy", "Portugal", "Spain") ~ "Southern",
country %in% c("Austria", "Belgium", "France", "Germany", "Netherlands", "Switzerland") ~ "Western"))
gm_europe_avg <- gm_europe %>%
group_by(country) %>%
mutate(mean_gdp = mean(gdpPercap),
mean_lifeexp = mean(lifeExp)) %>%
ungroup() %>%
filter(year == 2007)
I did this a little differently - instead of having each year’s data for the countries, I wanted to use the average life expectancy and GDP per capita for the entire study period. My hesitation here is that it looks like the average for 2007 is actually the average for the duration of the time series, but since I’m not using that column in this plot, I’m okay with it for now. If I were going to use this more, I suppose I would remove the year column or change the name of the average column to clarify?
Do the following:
geom_point()).europe_avg_plot <- ggplot(gm_europe_avg, aes(x = mean_lifeexp, y = mean_gdp, color = region)) +
geom_point(aes(text = country), size = 4) +
labs(title = "Average GDP and Life Expectancy in Europe (1952-2007)", x = "Average Life Expectancy", y = "Average GDP Per Capita", color = "Region")
## Warning in geom_point(aes(text = country), size = 4): Ignoring unknown
## aesthetics: text
europe_avg_plot
ggplotly().ggplotly(europe_avg_plot, tooltip = "text")
It is! I wish I could have figured out how to put in the average GDP and Life Expectancy in the tooltip too. But this is helpful!
Good luck and have fun!