Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
library( package = 'ggplot2')
# Coordenadas de las esquinas del Cuadro
cuadro <- data.frame( x = c(0,0,1,1,0)
, y = c(0,1,1,0,0)
)
# Coordenadas de la diagonal
recta <- data.frame( x = c(0,1)
, y = c(0,1)
)
# 15k puntos generados por medio de la distribución uniforme
puntos <- data.frame( x = runif(n = 15000 )
, y = runif(n = 15000 )
)
# Calcular distancia
puntos$dist <- round( x = abs( x = puntos$x - puntos$y ) / sqrt( x = 2 ), digits = 4 )
# Etiquetar observaciones
puntos$clase <- ifelse( test = puntos$dist < 0.1667
, yes = 'Menor'
, no = 'Mayor igual'
)
# Obtener proporciones
table(puntos$clase)
# Graficar
( ggplot()
+ geom_path( data = cuadro
, mapping = aes( x = x
, y = y
)
, size = 1
)
+ geom_path( data = recta
, mapping = aes( x = x
, y = y
)
, size = 1
)
+ geom_point( data = puntos
, mapping = aes( x = x
, y = y
, col = clase
)
, size = 0.1
)
+ guides( color=guide_legend( title="Clase") )
+ theme_bw()
+ theme( legend.position = 'bottom')
+ labs( x = 'X'
, y = 'Y'
)
+ coord_fixed()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.