EDIT: Added coord_fixed()
to ensure aspect ratio is correct, and some dummy points to stretch canvas.
Does this work? It is back to back geom_curves()
.
#Stackoverflow seed lens geom_curve
#question from:
#https://stackoverflow.com/questions/68433803/is-there-a-function-in-r-for-creating-an-ellipse-with-pointed-ends#comment120943747_68433803
#assistance from:
#https://stackoverflow.com/a/55627647/4927395
library(tidyverse)
df <- tribble(
~seed, ~h, ~w, ~row,
#----|----|---|---
"Oak", 5, 4, 1,
"Soy", 2, 2, 2,
"Rye", 4, 1, 3
)
df <- df %>% mutate(curvature = w/h)
ggplot() +
lapply(split(df, 1:nrow(df)), function(dat) {
geom_curve(data = dat, aes(x = row, y = -h/2, xend = row, yend = h/2), curvature = dat["curvature"]) }
) +
lapply(split(df, 1:nrow(df)), function(dat) {
geom_curve(data = dat, aes(x = row, y = h/2, xend = row, yend = -h/2), curvature = dat["curvature"]) }
)+
geom_point(aes(x=-2, y=0), colour = NA)+
geom_point(aes(x=5, y=0), colour = NA)+
geom_label(data = df, aes(x=row, y = 0, label = seed))+
coord_fixed(ratio = 1) +
#coord_cartesian(xlim = c(-2,nrow(df)+2))
ylab(NULL)+
ggsave("seeds.png")
and the result:
