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)