```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F, message = F)

library(ggplot2)
library(dplyr)
library(forcats)
```

# Scatterplot with regression line, rugs

```{r}
ggplot(data = mtcars,
       mapping = aes(x = hp, y = qsec)) +
  geom_point() + 
  geom_rug() +
  geom_smooth(method = "lm", color= "black") +
  scale_x_continuous(name = "Horse Power (HP)") +
  scale_y_continuous(name = "Quarter Mile Time (seconds)") +
  theme(panel.grid = element_blank(),
        panel.background = element_rect(color = "black", fill = NA, size = 1),
        axis.text = element_text(color = "black"))
```

# Lollipop plot

```{r}
# Create column of car names in mtcars
mtcars <- mtcars %>%
  arrange(mpg) %>%
  mutate(car = rownames(.),
         car = fct_relevel(car, as.character(car))) %>%
  as_tibble()
  
ggplot(data = arrange(mtcars, mpg)) +
  geom_segment(aes(x = car, xend = car, y = 0, yend = mpg)) +
  geom_point(aes(x = car, y = mpg), shape = 21, fill = "white", size = 3) +
  scale_x_discrete(name = "") +
  scale_y_continuous(name = "Miles Per Gallon (MPG)") +
  coord_flip() +
  theme(panel.background = element_rect(fill = "white"),
        panel.grid.major.x = element_line(color = "lightgray", size = .2),
        axis.text = element_text(color = "black"),
        axis.ticks.x = element_blank())
```