Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(data.table)
- library(ggplot2)
- dt <- data.table(party=c("'Dem ppl", "Repubs", "Wombats", "Kevin Bacon", "Trolls", "Good Space Guy", "Beer", "Ethics", "Goggles"),
- seats=c(57, 64, 5, 6, 7, 8, 56, 52, 57))
- dt$party <- factor(dt$party, levels=c("'Dem ppl", "Repubs", "Wombats", "Kevin Bacon", "Trolls", "Good Space Guy", "Beer", "Ethics", "Goggles"))
- (TOTAL <- sum(dt$seats))
- print(sum(dt[party %in% c("Beer", "Ethics", "Goggles")]$seats)/TOTAL)
- ggplot(dt, aes(x=party, seats, fill=party)) +
- geom_bar(stat = "identity") +
- scale_fill_brewer(palette="Set1") +
- theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
- # With stacks to be fair
- ggplot(dt, aes(x=factor(c(1,1, 2,3,4,5, 6,6,6)), seats, fill=party)) +
- geom_bar(stat = "identity") +
- scale_fill_brewer(palette="Set1") +
- labs(title="but let's also consider stacks, to be fair") +
- theme(axis.text.x = element_blank(),
- axis.title.x = element_blank(),
- axis.ticks.x = element_blank())
- # Pie charts can be good!
- (g <- ggplot(dt, aes(x="", seats, fill=party)) +
- geom_bar(stat = "identity", width=2, color="black") +
- coord_polar("y", direction=-1)) +
- scale_fill_brewer(palette="Set1") +
- labs(title="Ethical Beer Goggles ftw~") +
- geom_text(x=50, y=50, label="the real party", angle=-30) +
- # Trying to add a thick vertical line cutting the plot in half
- geom_segment(aes(x = 0, y = 0, xend = 2.5, yend = 0), linetype="longdash", size=1.2) +
- geom_segment(aes(x = 0, y = 156, xend = 2.5, yend = 156), linetype="longdash", size=1.2) +
- # Remove awkward polar coordinate crap and y-axis labels
- theme(axis.text = element_blank(),
- axis.ticks = element_blank(),
- panel.grid = element_blank(),
- axis.title.y = element_blank(),
- axis.title.x = element_blank())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement