Load the data
library(readr)
obama <- read_csv("ObamaApprovalRatingsSummer2010.csv")
## Rows: 13 Columns: 4
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Issue
## dbl (3): Approve, Disapprove, No Opinion
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(ggplot2)
library(ggthemes)
library(reshape)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ tibble 3.1.3 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.3 ✓ stringr 1.4.0
## ✓ purrr 0.3.4 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x tidyr::expand() masks reshape::expand()
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
## x dplyr::rename() masks reshape::rename()
Plot 1: Make the data long
longObama = gather(obama, Approval, Percentage, Approve:"No Opinion")
p1 = ggplot(longObama) +
geom_bar(aes(y = Percentage, x = Issue, fill = Approval),
stat = "identity")
# Reorder the issues
p1 = ggplot(longObama, aes(y = Percentage,
x = fct_reorder2(Issue,
Approval == "Approve", Percentage),
fill = factor(Approval, levels = c("No Opinion", "Disapprove", "Approve")))) +
geom_bar(stat = "identity")
p1

Plot 3: label the bar stuff
# if the bar reaches the certain size, show the label. Our space is limited.
p3 = p2 + geom_text(aes(label = ifelse(Percentage >= 0.15,
paste(sprintf("%.0f", Percentage*100)),
"")),
position = position_stack(vjust = 0.5), color = "white")
p3
