Overlapping Lines in ggplot2

前端 未结 1 637
太阳男子
太阳男子 2020-12-20 00:17

I fit 500 curves for two models. I plot each of the fits based on model to check for similarities. The trouble is one set of lines will overlay the other. In the example

相关标签:
1条回答
  • 2020-12-20 00:43

    Glad the alpha worked out for you. If you'd like to be able to accept + close the request you can just click on this example of added alpha (with some simulated data):

    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

    0 讨论(0)
提交回复
热议问题