Skip to content

Instantly share code, notes, and snippets.

@brshallo
Last active November 9, 2022 07:16
Show Gist options
  • Save brshallo/9526374dc0e4c7326fdd148349eb3bd8 to your computer and use it in GitHub Desktop.
Save brshallo/9526374dc0e4c7326fdd148349eb3bd8 to your computer and use it in GitHub Desktop.
library(dplyr)
library(ggplot2)
library(modeldata)

data(ames)

set.seed(123)
ames %>% 
  sample_n(200) %>%
  mutate(Sale_Price_Prior_Year = Sale_Price * rnorm(n(), 1, 0.15)) %>% 
  ggplot(aes(x = Sale_Price_Prior_Year, 
             y = Sale_Price, 
             size = Sale_Price, 
             colour = Sale_Price > Sale_Price_Prior_Year))+
  geom_point(alpha = 0.2)+
  geom_abline(slope = 1)+
  scale_x_log10(labels = scales::dollar)+
  scale_y_log10(labels = scales::dollar)+
  scale_size_continuous(labels = scales::dollar)+
  theme_bw()+
  labs(title = "Comparing this and last year's sale price", 
       colour = "Sale Price Increased",
       x = "Prior Year's Sale Price",
       y = "This Year's Sale Price")

set.seed(123)
ames %>% 
  sample_n(200) %>%
  mutate(Sale_Price_Prior_Year = Sale_Price * rnorm(n(), 1, 0.15)) %>% 
  ggplot(aes(x = Sale_Price_Prior_Year, 
             y = Sale_Price))+
  geom_bin2d()+
  geom_abline(slope = 1, colour = "red")+
  scale_x_log10(labels = scales::dollar)+
  scale_y_log10(labels = scales::dollar)+
  theme_bw()+
  labs(title = "Comparing this and last year's sale price", 
       x = "Prior Year's Sale Price",
       y = "This Year's Sale Price")

Created on 2022-11-08 by the reprex package (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment