Categories
BLOG

xname lab pipes

Xname lab pipes

GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

GitHub is where the world builds software

Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.

DeSheaToothakerIntroStats / chapter-05 / chapter-05.R

  • Go to file T
  • Go to line L
  • Copy path
rm( list = ls( all = TRUE )) # Clear the memory of variables from previous run. This is not called by knitr, because it’s above the first chunk.
# —- load-packages ——————————————————
library( magrittr ) # Pipes
library( ggplot2 ) # For graphing
requireNamespace( ” dplyr ” )
requireNamespace( ” scales ” )
requireNamespace( ” readr ” )
# —- declare-globals ——————————————————
source( ” ./common-code/book-theme.R ” )
theme_chapter theme_book
# —- load-data ——————————————————
dsObesity readr :: read_csv( ” ./data/food-hardship-obesity.csv ” )
dsPerfectPositive readr :: read_csv( ” ./data/chapter-05-perfect-positive.csv ” )
dsPerfectNegative readr :: read_csv( ” ./data/chapter-05-perfect-negative.csv ” )
dsStateBirthDeathRates readr :: read_csv( ” ./data/state-birth-death-rates.csv ” )
dsWorldMaternalMortality readr :: read_csv( ” ./data/world-maternal-mortality.csv ” )
dsStork readr :: read_csv( ” ./data/stork-birth.csv ” )
dsWorldBirthDeathRates readr :: read_csv( ” ./data/world-crude-births-deaths-cia.csv ” )
dsSmoking readr :: read_csv( ” ./data/smoking-tax.csv ” )
# —- tweak-data ——————————————————
dsWorldBirthDeathRates dsWorldBirthDeathRates % > %
tidyr :: drop_na( BirthsPer1000Pop ) % > %
tidyr :: drop_na( DeathsPer1000Pop ) % > %
dplyr :: mutate(
Omitted = ( BirthsPer1000Pop > = 30 )
)
dsSmoking $ Omitted ( dsSmoking $ TaxCentsPerPack > = 100 )
# —- figure-05-01 ——————————————————
# # Figure05_01 is linked to the first scatterplot in Chapter 03.
gObesity ggplot( dsObesity , aes( x = FoodHardshipRate , y = ObesityRate )) +
geom_point( shape = 21 , size = 3 , color = ” aquamarine4 ” , fill = adjustcolor( ” aquamarine4 ” , alpha.f = .1 )) + # This color should match the obesity Cleveland dot plot
scale_x_continuous( label = scales :: percent ) +
scale_y_continuous( label = scales :: percent ) +
coord_fixed() +
theme_chapter +
labs( x = ” Food Hardship Rate (in 2011) ” , y = ” Obesity Rate (in 2011) ” )
gObesity
# —- figure-05-02 ——————————————————
ggplot( dsPerfectPositive , aes( x = NumberOfLitersBought , y = Price )) +
geom_point( shape = 21 , size = 3 , color = ” #68663D ” , fill = ” #9BA47533 ” ) + # http://colrd.com/palette/17498/
scale_y_continuous( label = scales :: dollar ) +
theme_chapter +
labs( x = ” Number of Liters of Hand Sanitizer Purchased ” , y = ” Total Price (excluding taxes & shipping) ” )
# —- figure-05-03 ——————————————————
ggplot( dsPerfectNegative , aes( x = NumberScreened , y = GiftCardBudgetRemaining )) +
geom_point( shape = 21 , size = 3 , color = ” #68663D ” , fill = ” #9BA47533 ” ) + # http://colrd.com/palette/17498/
scale_y_continuous( label = scales :: dollar ) +
theme_chapter +
labs( x = ” Number of Adults Screened for Hypertension ” , y = ” Amount Remaining in Gift-Card Budget ” )
# —- figure-05-04 ——————————————————
ggplot( dsStateBirthDeathRates , aes( x = BirthRate2010 , y = DeathRateAgeAdjusted2010 )) +
geom_point( shape = 21 , size = 3 , color = ” #8C96FF ” , fill = ” #8C96FF22 ” ) + # Adapted from http://colrd.com/palette/18974/
theme_chapter +
labs( x = ” Birth Rate Per 1,000 Population (in 2010) ” , y = ” Age-Adjusted Death Rate \n per 100,000 Population (in 2010) ” )
# —- figure-05-05 ——————————————————
# See Recipe 5.9 in Chang, 2013 for writing the lm equations in the graph.
dsPlot dsObesity
xName ” FoodHardshipRate “
yName ” ObesityRate “
# m
# m
# eqn
# #substitute(italic(y)==a + b * italic(x) * “, “
  • Copy lines
  • Copy permalink
  • View git blame
  • Reference in new issue
  • © 2020 GitHub, Inc.
  • Terms
  • Privacy
  • Cookie Preferences
  • Security
  • Status
  • Help
  • Contact GitHub
  • Pricing
  • API
  • Training
  • Blog
  • About

You can’t perform that action at this time.

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.

Graphing code accompanying the book, *Introductory Statistics for the Health Sciences*, by Lise DeShea and Larry E. Toothaker (2015). Scroll down for the table of contents. – OuhscBbmc/DeSheaToothakerIntroStats