Skip to content

Instantly share code, notes, and snippets.

@Akiyah
Created September 22, 2014 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akiyah/0cc9687d10483c8d802b to your computer and use it in GitHub Desktop.
Save Akiyah/0cc9687d10483c8d802b to your computer and use it in GitHub Desktop.
x <- rnorm(20)
y <- rnorm(20)
p <- -0.9
u <- x + 2
v <- p * x + sqrt(1 - p**2) * y + 2
u <- (u - min(u)) / (max(u) - min(u))
v <- (v - min(v)) / (max(v) - min(v))
# plot(data.frame(x=u, y=v), pch=19, cex=1)
library(ggplot2)
g <- ggplot(data.frame(x=u, y=v),aes(x=x,y=y))
g <- g + geom_point(size=5)
g <- g + theme_bw(16)
g <- g + geom_smooth(method="lm")
g <- g + labs(x="", y="")
g <- g + ylim(0, 1)
plot(g)
ggsave(file=paste0("negative_correlation.png"), width=4, height=4, scale=1, dpi=800)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment