2

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

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

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

在此处输入图像描述

> 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")
4

1 回答 1

6

很高兴阿尔法为你解决了。如果您希望能够接受 + 关闭请求,您只需单击添加 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)

在此处输入图像描述

于 2013-06-02T14:59:31.860 回答