Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Create a point at an intersection of two circles using R

$
0
0

I'm trying to add a point on my plot at the intersection of two circles. Find below a sample of code. If adding a point is not possible, it could be useful to me to know the coordinates of the intersections.

A <- c(10, 11)
X <- c(0.245188, -1.199507)
Y <- c(-40.27914, -39.12006)
Di <- c(3.74, 5.18)
Mp <- c(19, 19)
df <- data.frame(Mp, A,  X, Y, Di)

library(ggplot2)
library(ggforce)

ggplot() + 
  geom_point(data=df, aes(X, Y)) +
  geom_circle(data=df, aes(x0 =X, y0 = Y, r = Di)) +
  geom_text(aes(X, Y, label = A), data = df, hjust = 1, vjust = 1) +
  coord_fixed() +
  theme_bw()

I've tried many but couldn't find the solution. Thanks for the help.

EDIT

I have a bigger data.frame How can I apply this to my df. Here's below a subset of my df

A <- c(10, 11, 12, 7)
X <- c(0.245188, -1.199507,-42.31990, -39.98215)
Y <- c(-40.27914, -39.12006, -2.734103, 3.181081)
Di <- c(3.74, 5.18, 5.39, 5.11)
Mp <- c(19, 19, 19, 19)
df <- data.frame(Mp, A,  X, Y, Di)

'''

Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>