library(phonTools)
library(Hmisc)
sim <- rmvtnorm(n =500, k=2, means = c(100, 100), sigma = 0.19)
real = sim[,1]
self_perceived = sim[,2]
groups <- cut2(real, g = 4)
means_real = tapply(real, groups, mean)
means_self_perceived = tapply(self_perceived, groups, mean)
plot(y = means_real, x = 1:4, type = "b", col = "red", xlab = "quartile", ylab = "ability" )
points(y = means_self_perceived, x = 1:4, type = "b", col = "blue")
legend(x = "bottomright", legend = c("real ability", "perceived ability"), col = c("red", "blue"), pch = 3)