Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Points in a scatterplot with individual ellipses using ggplot2 in R

My dataset is formed by 4 columns, as shown below: enter image description here

The two columns on the left represent the coordinates XY of a geographical structure, and the two on the left represent the size of "each" geographical unit (diameters North-South and East-West)

I would like to graphically represent a scatterplot where to plot all the coordinates and draw over each point an ellipse including the diameters of each geographical unit.

Manually, and using only two points, the image should be like this one: enter image description here

How can I do it using ggplot2?

You can download the data here

like image 604
antecessor Avatar asked May 11 '26 23:05

antecessor


1 Answers

Use geom_ellipse() from ggforce:

library(ggplot2)
library(ggforce)

d <- data.frame(
  x = c(10, 20),
  y = c(10, 20),
  ns = c(5, 8),
  ew = c(4, 4)
)

ggplot(d, aes(x0 = x, y0 = y, a = ew/2, b = ns/2, angle = 0)) + 
  geom_ellipse() +
  coord_fixed()

Created on 2019-06-01 by the reprex package (v0.2.1)

like image 61
Claus Wilke Avatar answered May 13 '26 15:05

Claus Wilke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!