¿Comó creo un circulo con radio sobre gráficos con ggplot?

Que tal, me gustaría crear un circulo que represente un sitio (De 1000m2) de muestreo con un radio = 17.84 m sobre gráficos de puntos que representan árboles, dejo un fragmento del código e imagen, los gráficos aparecen, solo el circulo no.

cDradi <- sqrt(1000/pi)
cDiam <- sqrt(1000/pi)*2

p <- ggplot(NNIN, aes(x, y, asp=1,
draw.circle(x=cDradi, y=cDradi, radius = cDradi)))+
geom_point(aes(size = DAP,colour = GENERO))
p + facet_wrap( ~ plot,nrow = 2, ncol = 4)+
scale_size(range = c(0,7))+
theme(legend.position="left")+theme_bw()+
coord_fixed()
#dev.off()

Estas mezclando funciones de R base y ggplot2.
Para poder hacerlo con ggplot2 necesitas primero generar los datos del circulo.

Aquí tienes una funcion que permite generar los datos de una circunferencia con centro -1, 1 diámetro 1 de 100 puntos.

circleFun <- function(center = c(-1, 1), diameter = 1, npoints = 100) {
  r <- diameter / 2
  tt <- seq(0, 2 * pi, length.out = npoints)
  xx <- center[1] + r * cos(tt)
  yy <- center[2] + r * sin(tt)
  return(data.frame(x = xx, y = yy))
}

Simplemente cambia el centro y el radio y tendras los datos para generar el circulo que quieres.
Después la puedes usar así:

ggplot(NNIN, aes(x, y, asp=1))+
geom_point(aes(size = DAP,colour = GENERO)) +
facet_wrap( ~ plot,nrow = 2, ncol = 4)+
scale_size(range = c(0,7))+
theme(legend.position="left")+theme_bw()+
coord_fixed() +
geom_path(aes(x, y), data = circleFun(c(0, 0), 17.84, npoints = 100)) 
1 Like

Muchas gracias, encontré una solución un poco más sencilla, así:

geom_circle(aes(x0 = 17.84124, y0 = 17.84124, r = 17.84124), col = "black", inherit.aes = FALSE)+

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.