Heatmap of regression lines

Viewed 1122

Suppose I run a bayesian simple linear regression. I would like to visualise the results by plotting multiple regression lines based on the posterior distributions of a (intercept) and b (slope). I am wondering how to display the results in a heatmap-like style or alternatively use transparency to avoid overlapping. Here's one simple ggplot approach.

library(ggplot2)
set.seed(123)

N = 1000
x = 1:80
a = rnorm(N,10,3)
b = rnorm(N,5,2)

y = vector("list",length=N)
for(i in 1:N) {y[[i]] = a[i]+b[i]*x}


df = data.frame(x=rep(x,N),y=unlist(y))
df$f = rep(1:N,each=80)

(plt <- ggplot(df, aes(x, y,group=f)) + 
  geom_jitter(alpha=1/30,width=5,col="blue") + theme_classic())

Are there better ways to do this? It would be nice if the colour would change depending on the amount of overlapping (as it is in heatmaps).

2 Answers
Related