r - 是否有用于创建带有尖椭圆或透镜的绘图的自定义几何图形或函数?
解决方案
编辑:添加coord_fixed()
以确保纵横比正确,并添加一些虚拟点来拉伸画布。
这行得通吗?它是背靠背的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")
推荐阅读
- javascript - 如何从文本文件中对多个数字(城市人口)进行分组?
- asp.net - IIS 10.0 上的旧 asp.net 应用程序无法识别元素“编译器”
- git - 通过修订从 gitpython 获取二进制文件(获取 unicodestring,需要字节)
- java - 为什么要使用 JSTL?当我们使用带有连接字符串的 JSP 文件中的数据库连接来获取从 servlet 发送的数据时会有什么危害
- regex - 正则表达式 - 介于两者之间
- javascript - 有人可以解释这个混淆语法的高阶 JavaScript 函数吗?
- vba - 将缩进带空格的文本转换为 PowerPoint 有序/无序列表?
- spring - Tomcat 9 连接器如何监听 127.0.0.1 反向代理到 Win。具有私有 ServerName 的 Apache 2.4
- json - 如何从 Json Play 框架中选择多个字段?
- for-loop - For Looping 不会更改 Katalon Studio 中的变量