gpt4 book ai didi

r - R中系统发育图上的彩色线条

转载 作者:行者123 更新时间:2023-12-04 10:48:56 25 4
gpt4 key购买 nike

在 RI 中,我想制作一些图表,其中我使用彩色线条,如下例所示。也许我可以使用彼此相邻的不同线来做到这一点,但问题是很难使用正确的线宽,以便它们彼此紧挨着放置,中间没有任何空白(因为 lwd 参数R 图形包中的线条不是绝对坐标)。是否有任何其他方法可以指定我想用两种或三种(或更多)不同的颜色绘制一条线? (理想情况下,角和线帽应该看起来不错)

干杯,汤姆

PS 我正在处理的应用程序是能够绘制具有多态状态的系统发育,如下图所示

enter image description here

enter image description here

enter image description here

enter image description here

最佳答案

根据我从 par 的帮助中收集到的信息,lwd 参数因设备而异。对于 x11,它声明“由 par(lwd =) 控制的线宽是 1/96 英寸的倍数”。基于定义的 lwd,我需要将此宽度转换为图形的 x 和 y 单位,以便正确偏移以下线条。

所以现在我让你的线条能够转弯 - 仍然需要对线条进行一些调整,以使它们以相同的长度结束(例如,从系列中的最后一个值中减去偏移量)。

示例:

x <- c(1:10, rep(1, 10))
y <- c(rep(1, 10), 1:10)
lwd <- 20

x11() #lwd is multiples of 1/96 inches (from help info)

plot(y ~ x, t="l", lend=2, ljoin=2, lwd=lwd, col=3, xlim=c(0,11), ylim=c(0,11))

x.units.per.inch <- (par("usr")[2] - par("usr")[1]) / par("pin")[1]
y.units.per.inch <- (par("usr")[4] - par("usr")[3]) / par("pin")[2]

x.offset <- x.units.per.inch * 1/96 * lwd
y.offset <- y.units.per.inch * 1/96 * lwd

lines(x + x.offset, y + y.offset, lend=2, ljoin=2, lwd=lwd, col=2)
lines(x - x.offset, y - y.offset, lend=2, ljoin=2, lwd=lwd, col=4)

enter image description here

关于r - R中系统发育图上的彩色线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17200131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com