Reflecting on the past week I would say that there was a lot of new content covered especially with flexdashboard and interactive plots. Unfortunately I missed a couple of classes and felt like I was lacking behind but I caught up after reviewing the slides.
I found this really interesting especially the interactive plots. It was really easy to get a hang of and work with. I am excited to work more with it for future projects
For this data viz challenge I used the dataset from data viz challenge 6. This code below picks the county with the most votes from five states (Arizona, California, Texas, Florida, and New York). It then creates a scatter plot that shows the percentage of Democratic votes in each top county, with the size representing the population. The x-axis labels are angled to make them easier to read. Using plotly, the plot becomes interactive, so you can hover over each point to see the county name, vote percentage, and population details.
library(tidyverse)
library(plotly)
library(ggplot2)
results_2016 <- read_csv("/Users/ibrahimrafiq/Desktop/data viz 6/results_2016.csv")
Do the following:
Make a plot. Any kind of plot will do (though it might be easiest
to work with geom_point()).
Make the plot interactive with ggplotly().
Make sure the hovering tooltip is more informative than the default.
Good luck and have fun!
top_county_per_state <- results_2016 %>%
filter(state %in% c("Arizona", "California", "Texas", "Florida", "New York")) %>%
group_by(state) %>%
filter(totalvotes == max(totalvotes, na.rm = TRUE))
my_plot <- ggplot(
data = top_county_per_state,
mapping = aes(x = state, y = percent_dem, color = total_population)
) +
geom_point(aes(label = county)) +
labs(
title = "Percentage of Democratic Votes by Top County in Each State",
x = "State",
y = "Percentage Democratic Votes",
color = "Total Population"
) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
## Warning in geom_point(aes(label = county)): Ignoring unknown aesthetics: label
interactive_plot <- ggplotly(
my_plot, tooltip = c("label", "y", "color")
)
interactive_plot
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.