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 7978457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:29:48+00:00 2026-06-04T09:29:48+00:00

There’s a nice explanation here of how to use ggplot2 to create a scatterplot,

  • 0

There’s a nice explanation here of how to use ggplot2 to create a scatterplot, fit the data using nls, and plot the fit, all in one line, like so

myhist = data.frame(size = 10:27, counts = c(1L, 3L, 5L, 6L, 9L, 14L, 13L, 23L, 31L, 40L, 42L, 22L, 14L, 7L, 4L, 2L, 2L, 1L) )

ggplot(data=myhist, aes(x=size, y=counts)) + geom_point() + 
    geom_smooth(method="nls", formula = y ~ N * dnorm(x, m, s), se=F, 
    start=list(m=20, s=5, N=300)) 

My question is: using this construction, is it possible to pull out the actual nls object from that call? I’d like to know my coefficients, etc. Right now I can’t figure out how to get them without doing a separate nls call.

  • 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-04T09:29:48+00:00Added an answer on June 4, 2026 at 9:29 am

    My question is: using this construction, is it possible to pull out the actual nls object from that call? I’d like to know my coefficients, etc.

    This is currently not possible in ggplot2. The ggplot2 functions return predictions from the model, but not the model object itself. Thus, you cannot extract an nls object from the ggplot object to find the coefficients, etc.

    There are two relevant discussions in the ggplot2 and ggplot2-dev mailing lists:

    https://groups.google.com/d/topic/ggplot2/7tiUB2sjCxM/discussion

    https://groups.google.com/d/topic/ggplot2-dev/dLGJnzIg4ko/discussion

    Quick synopsis:

    While many users have asked for the ability to extract statistics from ggplot objects, the developers are considering it but seem somewhat opposed. They would prefer users to use ggplot2 for visualization, and appropriate modelling functions to explore modelling parameters. However, Hadley supports the idea of implementing the ability to pass a model object to a ggplot() call. So, instead of trying to extract the nls object from your ggplot object, you would instead:

    mod <- nls(y ~ N * dnorm(x, m, s), se = F, start = list(m = 20, s = 5, N = 300), 
            data = myhist)
    ggplot(data = myhist, aes(x = size, y = counts)) + geom_point() + 
            geom_smooth(mod) 
    

    That way, the model only needs to be called once, you can do anything you want to it, and you don’t have to go searching through ggplot objects to find it. However, I don’t know when or if this will be implemented.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There seem to be very different opinions about using transactions for reading from a
There seems to be a similar question to this on here but with the
There seems to be too many attributes/parameters in CSS... I want to know all
There exists an RSS feed with over 1000 items. I want to create a
There will be 500+ threads concurrently uploading an unique object to a bucket all
There are 3 different ways to get data out of a BLOB column from
There is a known issue with using jquery fadeOut, fadeIn, and fadeToggle, when fading
There are lots of posts on here about moving a folder out of one
There is a constant I'm using from the iOS SDK. I printed out the
There are two ways to get a NSManagedObjectContext that I know of: create a

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.