September 21, 2017
Any questions from last time?
Any questions from the reading?
Read: http://slate.me/1dr5XPE
"Good coding style is like correct punctuation: you can manage without it, butitsuremakesthingseasiertoread." - Hadley Wickham
Style guide for this course is based on the Tidyverse style guide: http://style.tidyverse.org/
There's more to it than what we'll cover today, but we'll mention more as we introduce more functionality, and do a recap later in the semester
-
or _
to separate words# Good ucb-admit.csv # Bad UCB Admit.csv
_
to separate words in object names# Good acs_employed # Bad acs.employed acs2 acs_subset acs_subsetted_for_males
# Good average <- mean(feet / 12 + inches, na.rm = TRUE) # Bad average<-mean(feet/12+inches,na.rm=TRUE)
+
# Good ggplot(diamonds, mapping = aes(x = price)) + geom_histogram() # Bad ggplot(diamonds,mapping=aes(x=price))+geom_histogram()
Limit your code to 80 characters per line. This fits comfortably on a printed page with a reasonably sized font.
Take advantage of RStudio editor's auto formatting for indentation at line breaks.
<-
not =
# Good x <- 2 # Bad x = 2
Use "
, not '
, for quoting text. The only exception is when the text already contains double quotes and no single quotes.
ggplot(diamonds, mapping = aes(x = price)) + geom_histogram() + # Good labs(title = "`Shine bright like a diamond`", # Good x = "Diamond prices", # Bad y = 'Frequency')
What relationship would you expect to see between average SAT scores and average salaries of teachers?
Data are from 1997! The dataset is in the moasicData
package, and we will also make use of dplyr
and ggplotot2
.
library(mosaicData) library(ggplot2) library(dplyr)
ggplot(SAT, mapping = aes(x = salary, y = sat)) + geom_point() + geom_smooth(method = "lm", se = FALSE)
SAT <- SAT %>% mutate(frac_cat = case_when( frac <= 22 ~ "low", frac > 22 & frac <= 49 ~ "medium", frac > 50 ~ "high" ))
Describe the relationship between average SAT scores and average salaries of teachers?
ggplot(SAT, mapping = aes(x = salary, y = sat, color = frac_cat)) + geom_point() + geom_smooth(method = "lm", se = FALSE)
Let's get started on Mini HW 6: