You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A basic violin plot showing how Democratic vote share in the 2018 elections to the US House of Representatives varied by level of density. A horizontal bar is added, to divide candidates who lost from those who won.
241
-
242
-
Source: [Dave Wassermann and Ally Flinn](https://docs.google.com/spreadsheets/d/1WxDaxD5az6kdOjJncmGph37z0BPNhV1fNAH_g7IkpC0/htmlview?sle=true#gid=0) for the election results and CityLab for its [Congressional Density Index](https://github.com/theatlantic/citylab-data/tree/master/citylab-congress). Regional classifications are according to the Census Bureau.
p <- ggplot(district_density,aes(x=cluster, y=dem_margin, fill=cluster)) +
275
-
geom_violin(colour=NA) +
276
-
geom_hline(yintercept=0, alpha=0.5) +
277
-
facet_wrap(~region) +
278
-
labs(title = "Democratic performance in the 2018 House elections, by region and density",
279
-
x = "Density Index\nfrom CityLab",
280
-
y = "Margin of Victory/Defeat") +
281
-
coord_flip()
282
-
283
-
ggplotly(p)
284
-
```
285
-
286
-
### Customized Appearance
287
206
Add colour to the facet titles, centre-align the title, rotate the y-axis title, change the font, and get rid of the unnecessary legend. Note that `coord_flip()` flips the axes for the variables and the titles, but does not flip `theme()` elements.
0 commit comments