Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8803061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:14:35+00:00 2026-06-14T01:14:35+00:00

I have a list of linear and non-linear models derived from different data sets

  • 0

I have a list of linear and non-linear models derived from different data sets measuring the same two variables x and y that I would like to plot on the same plot using stat_smooth. This is to be able to easily compare the shape of the relationship between x and y across datasets.

I’m trying to figure out the most effective way to do this. Right now I am considering creating an empty ggplot object and then using some kind of loop or lapply to add sequentially to that object, but this is proving more difficult than I thought. Of course it would be easiest to simply supply the models to ggplot but as far as I know, this is not possible. Any thoughts?

Here is a simple example data set to play with using just two models, one linear and one exponential:

df1=data.frame(x=rnorm(10),y=rnorm(10))
df2=data.frame(x=rnorm(15),y=rnorm(15))

df.list=list(lm(y~x,df1),nls(y~exp(a+b*x),start=list(a=1,b=1),df2))

And two separate example plots:

ggplot(df1,aes(x,y))+stat_smooth(method=lm,se=F)
ggplot(df2,aes(x,y))+stat_smooth(method=nls,formula=y~exp(a+b*x),start=list(a=1,b=1),se=F)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:14:37+00:00Added an answer on June 14, 2026 at 1:14 am

    I think the answer here is to get a common range of X and Y you want to run this over, and go from there. You can pull out a curve from each model using predict, and add on layers to a ggplot using l_ply.

    d

    f1=data.frame(x=rnorm(10),y=rnorm(10))
    df2=data.frame(x=rnorm(15),y=rnorm(15))
    
    df.list=list(lm(y~x,df1),nls(y~exp(a+b*x),start=list(a=1,b=1),df2))
    
    
    a<-ggplot()
    
    
    #get the range of x you want to look at
    x<-seq(min(c(df1$x, df2$x)), max(c(df1$x, df2$x)), .01)
    
    #use l_ply to keep adding layers
    l_ply(df.list, function(amod){
    
      #a data frame for predictors and response
      ndf <- data.frame(x=x)
    
      #get the response using predict - you can even get a CI here
      ndf$y <- predict(amod, ndf)
    
      #now add this new layer to the plot
      a<<- a+geom_line(ndf, mapping=(aes(x=x, y=y)))
    
    } )
    
    a
    

    OR, if you want to have a nice color key with model number or something:

    names(df.list) <- 1:length(df.list)
    modFits <- ldply(df.list, function(amod){
      ndf <- data.frame(x=x)
    
      #get the response using predict - you can even get a CI here
      ndf$y <- predict(amod, ndf)
    
      ndf
    
      })
    
    
    qplot(x, y, geom="line", colour=.id, data=modFits)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a linear linked list that consists of nodes: class Node{ Object data;
I have list of structure. I want to modify a particular data from the
I have a blank linear list, I've got a list of images that will
i have list of rows that user select and i want to delete them,
I have a javascript object literal? I access them in my webpage as data.list[i].ger
I have a linear list of zeros and ones and I need to match
I have a list view full of items that contain multiple widgets each such
I have a DAG representing a list of properties. These properties are such that
I have a large list of integers that are sent to my webservice. Our
I have a script that turns an unordered list of images into a horizontal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.