-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoriginal.R
34 lines (28 loc) · 924 Bytes
/
original.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Instruction to students: You may clear the code in this file and replace it
# with your own.
library(tidyverse)
library(ggforce)
theme_set(theme_void())
# Draw a random chord in a unit circle centred at origin -----------------------
# Coordinates of equilateral triangle
eqtri_df <- tibble(
x = c(0, sqrt(3) / 2, -sqrt(3) / 2),
y = c(1, -0.5, -0.5),
xend = c(sqrt(3) / 2, -sqrt(3) / 2, 0),
yend = c(-0.5, -0.5, 1)
)
# Coordinates of random chord
rdmchr_df <- tibble(
x = 0.93636368,
y = 0.35103142,
xend = -0.9999991,
yend = -0.001326758
)
# Plot
p <- ggplot() +
ggforce::geom_circle(aes(x0 = 0, y0 = 0, r = 1), col = "gray50") +
geom_segment(data = eqtri_df, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_segment(data = rdmchr_df, aes(x = x, y = y, xend = xend, yend = yend),
col = "red3") +
coord_equal()
ggsave(p, file = "plot.png", height = 5, width = 7)