trallard
2/28/2018 - 9:25 AM

R_snippets

General R snippets useful for data wrangling and things

# your code to create graph as seen in book
table2 %>% 
  filter(type == "cases") %>% str()
  ggplot(aes(year, count)) +
  geom_line(aes(group = country), color = "grey50") +
  geom_point(aes(color = country)) +
  scale_x_continuous(breaks = c(1999.00, 1999.25, 1999.50, 1999.75, 2000.00),
                   labels = c(1999, 1999, 2000, 2000, 2000))

# raw code from book 
## (which doesn't make the graph seen in book >.<)
ggplot(table1, aes(year, cases)) + 
  geom_line(aes(group = country), colour = "grey50") + 
  geom_point(aes(colour = country))
diamonds %>%
  count(cut, color) %>%
  mutate(prop1 = n / sum(n)) %>%
  ggplot() +
  geom_col(mapping = aes(x = cut, fill = color, y = prop1))