Last active
February 24, 2020 17:42
-
-
Save jsajuria/96e1be364c70b57fe87f452d8db9a1c5 to your computer and use it in GitHub Desktop.
Simulación Puntajes PSU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(hrbrthemes) | |
library(truncnorm) | |
set.seed(100) | |
psu <- data.frame(puntaje = rtruncnorm(10000,150,850,500,110)) | |
#baseline | |
p <- ggplot(psu, aes(x=puntaje)) | |
# Linea de promedio y ejes | |
p <- p + geom_density(col = "#9986A5") + theme_ipsum_rc() + | |
theme(panel.grid.major.x = element_blank(), | |
panel.grid.minor = element_blank(), | |
axis.line = element_line(size = 1, colour = "darkgrey")) | |
# Lineas de una desviación estándar a cada extremo | |
p <- p + geom_segment(aes(x = 500, y = 0, xend = 500, yend = 0.00365), color="#9986A5",linetype="dashed") + | |
geom_segment(aes(x = 390, y = 0, xend = 390, yend = 0.0022), color="#C6CDF7",linetype="dashed") + | |
geom_segment(aes(x = 610, y = 0, xend = 610, yend = 0.0022), color="#C6CDF7",linetype="dashed") | |
# Lineas de 1.96 desviaciones estándar | |
p <- p + geom_segment(aes(x = 284.4, y = 0, xend = 284.4, yend = 0.0005), color="#C6CDF7",linetype="dashed") + | |
geom_segment(aes(x = 715.6, y = 0, xend = 715.6, yend = 0.0005), color="#C6CDF7",linetype="dashed") | |
# texto | |
p <- p + annotate(geom = "text", | |
x = 250, y = 0.0001, | |
label = "2,5%") + | |
annotate(geom = "text", | |
x = 350, y = 0.0001, | |
label = "13,5%") + | |
annotate(geom = "text", | |
x = 450, y = 0.0001, | |
label = "34%") + | |
annotate(geom = "text", | |
x = 550, y = 0.0001, | |
label = "34%") + | |
annotate(geom = "text", | |
x = 650, y = 0.0001, | |
label = "13,5%") + | |
annotate(geom = "text", | |
x = 750, y = 0.0001, | |
label = "2,5%") | |
# Titulo y comentarios | |
p <- p + | |
labs(title = "Distribución puntajes PSU", | |
subtitle = "El promedio se estandariza en 500 con una desviación estándar de 110. \nAdemás la distribución se trunca, ya que nadie puede tener menos de 150 ni más de 850 puntos", | |
caption = "Fuente: Simulación \n Javier Sajuria") + | |
scale_x_continuous("Puntajes", | |
breaks = c(150,200,300,400,500,600,700,800,850)) + | |
scale_y_continuous("", breaks = c()) | |
p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment