gpt4 book ai didi

r - ggplot2 中的重叠线

转载 作者:行者123 更新时间:2023-12-02 17:44:15 25 4
gpt4 key购买 nike

我为两个模型拟合了 500 条曲线。我根据模型绘制每个拟合以检查相似性。问题是一组线会覆盖另一组线。在下面的示例中,逻辑线完全被样条线覆盖。

有没有一种方法可以绘制两个拟合图并防止重叠,这样我仍然可以看到两组线?也许通过改变颜色或使用不同的几何图形?

ggplot(data=fullData,aes(X,Y,color=Model,group=id))+geom_line()

enter image description here

> dput(head(fullData))
structure(list(X = c(-6, -5.97595190380762, -5.95190380761523,
-5.92785571142285, -5.90380761523046, -5.87975951903808), Model = c("Logistic",
"Logistic", "Logistic", "Logistic", "Logistic", "Logistic"),
Y = c(40.2327812336246, 40.2062250618146, 40.1837765087578,
40.1613100197852, 40.1387156930829, 40.1159930605682), id = c(1L,
1L, 1L, 1L, 1L, 1L)), .Names = c("X", "Model", "Y", "id"), row.names = c(NA,
6L), class = "data.frame")

最佳答案

很高兴 alpha 为您解决了。如果您希望能够接受 + 关闭请求,您只需单击这个添加的 alpha 示例(带有一些模拟数据):

library(ggplot2)

#function to generate some data
makeLine <- function(x){
set.seed(x)
Y <- c(runif(1,38,42),runif(1,34,38),runif(1,28,32),runif(1,23,27),runif(1,10,20))
X <- c(-6,-3,0,3,6)
if(x > 40){
model <- "Spline"
} else {
model <- "Logistic"
}
data.frame(X=X,Y=Y,id=x,model=model)
}

#make a data set
dat <- do.call(rbind,lapply(1:100,makeLine))

#add alpha to your plot
ggplot(data=dat,aes(X,Y,color=model,group=id)) + geom_line(alpha=0.15)

enter image description here

关于r - ggplot2 中的重叠线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16874501/

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