A visualization of the 2019 U.S. google search trends of the terms “Intel” and “AMD” with an animated map of the same trends from 2006 to 2020.
Intel
AMD
animate(map, start_pause = 15, end_pause = 15, renderer = )
> Red is AMD and Blue is Intel.
library(ggplot2)
library(ggmap)
library(maps)
library(mapdata)
library(stringr)
library(dplyr)
library(gganimate)
library(tidyr)
library(readxl)
library(plotly)
aggregated <- read_excel("aggregated.xlsm")
aggregated <- aggregated %>% rename(region = "state")
aggregated$region <- tolower(aggregated$region)
states <- map_data("state")
state_data <- inner_join(states, aggregated, by="region")
state_intel <- select(state_data, long, lat, group, order, region, `intel: (2006)`, `intel: (2007)`, `intel: (2008)`, `intel: (2009)`, `intel: (2010)`, `intel: (2011)`, `intel: (2012)`, `intel: (2013)`, `intel: (2014)`, `intel: (2015)`, `intel: (2016)`, `intel: (2017)`, `intel: (2018)`, `intel: (2019)`, `intel: (2020)`) %>%
rename(`2006` = `intel: (2006)`, `2007` = `intel: (2007)`, `2008` = `intel: (2008)`, `2009` = `intel: (2009)`, `2010` = `intel: (2010)`, `2011` = `intel: (2011)`, `2012` = `intel: (2012)`, `2013` = `intel: (2013)`, `2014` = `intel: (2014)`, `2015` = `intel: (2015)`, `2016` = `intel: (2016)`, `2017` = `intel: (2017)`, `2018` = `intel: (2018)`, `2019` = `intel: (2019)`, `2020` = `intel: (2020)`) %>% gather(`Intel`, "Intel trend", `2006`:`2020`)
state_intel$Intel <- as.numeric(as.character(state_intel$Intel))
state_amd <- select(state_data, long, lat, group, order, region, `amd: (2006)`, `amd: (2007)`, `amd: (2008)`, `amd: (2009)`, `amd: (2010)`, `amd: (2011)`, `amd: (2012)`, `amd: (2013)`, `amd: (2014)`, `amd: (2015)`, `amd: (2016)`, `amd: (2017)`, `amd: (2018)`, `amd: (2019)`, `amd: (2020)`) %>%
rename(`2006` = `amd: (2006)`, `2007` = `amd: (2007)`, `2008` = `amd: (2008)`, `2009` = `amd: (2009)`, `2010` = `amd: (2010)`, `2011` = `amd: (2011)`, `2012` = `amd: (2012)`, `2013` = `amd: (2013)`, `2014` = `amd: (2014)`, `2015` = `amd: (2015)`, `2016` = `amd: (2016)`, `2017` = `amd: (2017)`, `2018` = `amd: (2018)`, `2019` = `amd: (2019)`, `2020` = `amd: (2020)`) %>% gather(`AMD`, "AMD trend", `2006`:`2020`)
state_amd$AMD <- as.numeric(as.character(state_amd$AMD))
us <- map_data("usa")
us_base <- ggplot(data = us, mapping = aes(x = long, y = lat, group = group)) +
coord_fixed(1.3) +
geom_polygon(color = "black", fill = "NA")
#AMD animation
mid <- mean(state_amd$`AMD trend`)
ditch_the_axes <- theme(
axis.text = element_blank(),
axis.line = element_blank(),
axis.ticks = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank(),
axis.title = element_blank()
)
map <- us_base +
geom_polygon(data = state_amd, aes(fill = `AMD trend`), color = "white") +
geom_polygon(color = "black", fill = NA) +
theme_bw() +
ditch_the_axes +
transition_time(AMD) +
labs(title = 'Year: {frame_time}')+
scale_fill_gradient2(midpoint = mid, low = "blue", mid = "white", high = "red")
USMap <- read_excel("USMap.xlsx")
base.df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv")
strip.me <- base.df %>% select(code,state)
RvB.df <- left_join(strip.me,USMap, by="state")
RvB.df <- RvB.df %>% mutate(hover = paste(state,'<br>',"Intel:", Intel,'<br>', "AMD:",AMD))
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showlakes = TRUE,
lakecolor = toRGB('white')
)
Intel <- plot_geo(RvB.df, locationmode = 'USA-states') %>%
add_trace(z = ~Intel, text = ~hover, locations = ~code,
color = ~Intel, colors = 'Blues') %>%
colorbar(title = "Intel Google Search") %>%
layout(
title = 'Interest in Intel',
geo = g
)
AMD <- plot_geo(RvB.df, locationmode = 'USA-states') %>%
add_trace(z = ~AMD, text = ~hover, locations = ~code,
color = ~AMD, colors = 'Reds') %>%
colorbar(title = "AMD Google Search") %>%
layout(
title = 'Interest in AMD',
geo = g
)