socviz

Data Vis Chapter 8

Use Color Palette Layer Color and Text Together Themes Use Theme Elements Two y-axes head(asasec) ## Section Sname Beginning Revenues ## 1 Aging and the Life Course (018) Aging 12752 12104 ## 2 Alcohol, Drugs and Tobacco (030) Alcohol/Drugs 11933 1144 ## 3 Altruism and Social Solidarity (047) Altruism 1139 1862 ## 4 Animals and Society (042) Animals 473 820 ## 5 Asia/Asian America (024) Asia 9056 2116 ## 6 Body and Embodiment (048) Body 3408 1618 ## Expenses Ending Journal Year Members ## 1 12007 12849 No 2005 598 ## 2 400 12677 No 2005 301 ## 3 1875 1126 No 2005 NA ## 4 1116 177 No 2005 209 ## 5 1710 9462 No 2005 365 ## 6 1920 3106 No 2005 NA p <- ggplot( data = subset(asasec, Year == 2014), mapping = aes(x = Members, y = Revenues, label = Sname) ) p + geom_point() + geom_smooth() p <- ggplot( data = subset(asasec, Year == 2014), mapping = aes(x = Members, y = Revenues, label = Sname) ) p + geom_point(mapping = aes(color = Journal)) + geom_smooth(method = "lm") p0 <- ggplot( data = subset(asasec, Year == 2014), mapping = aes(x = Members, y = Revenues, label = Sname) ) p1 <- p0 + geom_smooth(method = "lm", se = FALSE, color = "gray80") + geom_point(mapping = aes(color = Journal)) library(ggrepel) p2 <- p1 + geom_text_repel(data = subset(asasec, Year == 2014 & Revenues > 7000), size = 2) p3 <- p2 + labs( x = "Membership", y = "Revenues", color = "Section has own Journal", title = "ASA Sections", subtitle = "2014 Calendar year.

Data Vis Chapter 6

Show Several Fits at Once, with a Legend Model-based Graphics Tidy Model Objects with Broom get component-level statistics with tidy() Get observation-level statistics with augment() Grouped Analysis Plots for Surveys p <- ggplot(data = gapminder, mapping = aes(x = log(gdpPercap), y = lifeExp)) p + geom_point(alpha = 0.1) + geom_smooth(color = "tomato", fill = "tomato", method = MASS::rlm) + #robust regression line geom_smooth(color = "steelblue", fill = "steelblue", method = "lm") p + geom_point(alpha = 0.

Data Visualization Chapter 2-4

Chapter 2 Chapter 3 Wrong way to set color Aesthetics Can Be Mapped per Geom Save plots Chapter 4 Group data and the “Group” Aesthetic Facet to make small multiples Geoms can transform data Histgrams and Density Plots Avoid Transformations When Necessary Chapter 2 geom_point p <- ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp)) p + geom_point() Chapter 3 geom_smooth

Data Visualization Chapter 5

Chapter 5 Use Pipes to Summerize Data Continuous Variables by Group or Category Write and Draw in the Plot Area Scales, Guides, and Themes Chapter 5 Use Pipes to Summerize Data rel_by_region <- gss_sm %>% group_by(bigregion, religion) %>% summarize(N = n()) %>% mutate(freq = N / sum(N), pct = round((freq*100), 0)) ## Warning: Factor `religion` contains implicit NA, consider using ## `forcats::fct_explicit_na` rel_by_region ## # A tibble: 24 x 5 ## # Groups: bigregion [4] ## bigregion religion N freq pct ## <fct> <fct> <int> <dbl> <dbl> ## 1 Northeast Protestant 158 0.