Skip to content

Instantly share code, notes, and snippets.

@achetverikov
Created April 30, 2021 12:39
Show Gist options
  • Save achetverikov/5fbd5535686cb20ad78f167c04485659 to your computer and use it in GitHub Desktop.
Save achetverikov/5fbd5535686cb20ad78f167c04485659 to your computer and use it in GitHub Desktop.
DatasauRus as the noisy data
library(datasauRus)
library(data.table)
library(ragg)
library(ggplot2)
dsd <- datasaurus_dozen
setDT(dsd)
dsd <- dsd[dataset%in%c('star','dino','away', 'circle')]
dsd[,z:=rnorm(.N, sd = 0.4)]
dsd[,y_new:=0.2*x+z+y, by = dataset]
res = 320
ragg::agg_png('dsd_1.png', res = res, width = 4*res, height = 4*res)
ggplot(dsd, aes(x = x, y = y_new))+facet_wrap(~dataset)+geom_point()+labs(y = 'y', x = 'x')+theme(strip.text = element_blank())
dev.off()
ragg::agg_png('dsd_2.png', res = res, width = 4*res, height = 4*res)
ggplot(dsd, aes(x = x, y = y_new-y))+facet_wrap(~dataset)+geom_point()+labs(y = 'y after removing confounds', x = 'x')+theme(strip.text = element_blank())
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment