Skip to content

Instantly share code, notes, and snippets.

@steveharoz
Created July 26, 2023 06:41
Show Gist options
  • Save steveharoz/ae0375ba2b20c3a92519749412fcebda to your computer and use it in GitHub Desktop.
Save steveharoz/ae0375ba2b20c3a92519749412fcebda to your computer and use it in GitHub Desktop.
library(tidyverse)
library(modelr) # add_predictions
tibble(
x = (-2:2) * 1.1,
y = c(1, -1.9, 2, 1.9, -.75),
weight = c(0.6, 2.5, 1, 1, 0.8)
) %>%
modelr::add_predictions(lm(y ~ x, ., weights=.$weight)) %>%
ggplot() +
aes(x=x, y=y) +
geom_point(size = 20, color="white") +
geom_smooth(aes(weight=weight), method = "lm", se = F, fullrange=TRUE, linewidth = 16, lineend="round", color="white") +
geom_segment(aes(xend=x, y=pmax(y, pred)-0.3, yend=pmin(y, pred)+0.33), linewidth=5, linetype = "42", color="white", alpha = 0.5) +
expand_limits(x=c(-2.5, 2.5), y=c(-2.5, 2.5)) +
coord_equal() +
theme_void() + theme(
plot.background = element_rect(fill = "#640000"),
plot.margin = margin(20,20,20,20)
)
# save from RStudio with 1000x1000 resolution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment