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

  • Home
  • SEARCH
  • 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 8983617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:53:04+00:00 2026-06-15T20:53:04+00:00

So Im using nls in ggplot2 to plot a power curve code is below:

  • 0

So Im using nls in ggplot2 to plot a power curve code is below:

mass <- c(4120,4740,5550,5610,6520,6870,7080,8500,8960,10350,10480,10550,11450,11930,12180,13690,13760,13800,14050,14700,15340,15790,15990,17300,18460,18630,18650,20050,23270,24530,25030,27540,28370,33460,33930,34450,34500)

solv_acc <- c(2760,2990,2990,3180,3900,4010,4140,4680,4750,5330,4980,5860,5930,5570,5910,6790,6690,7020,6240,6620,6600,6860,7940,7600,8250,8530,7410,9160,9140,10300,10440,10390,11020,12640,11920,12110,12650)

df <- data.frame(Mass=log(mass),Solv=log(solv_acc))

plotter <- (ggplot(df, aes(x=Mass, y=Solv)) + geom_point(shape=1) + stat_smooth(method = "nls", formula = y~i*x^z, start=list(i=1,z=0.2)))
plotter <-  plotter + labs(x = "Mass kDa" ,y = "Solvent Accessibility")
print(plotter)

Running the above code I get the following error:

Error in pred$fit : $ operator is invalid for atomic vectors

I am assuming the error occurs when it tries to use predict()?

When I perform nls without the use of ggplot2 on the same data frame I do not get an error

> nls1=nls(Solv~i*Mass^z,start=list(i=1,z=0.2),data=df)
> predict(nls1)
 [1] 7.893393 7.997985 8.115253 8.123230 8.234519 8.273135 8.295350 8.429871 8.468550 8.574147 8.583270 8.588134 8.647895 8.677831 8.692939 8.777944 8.781648 8.783757 8.796793 8.829609
[21] 8.860502 8.881445 8.890558 8.947512 8.994380 9.000995 9.001769 9.053953 9.161073 9.198919 9.213390 9.281841 9.303083 9.420894 9.430834 9.441670 9.442703

Can anyone point out why I am getting the error?

  • 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-15T20:53:05+00:00Added an answer on June 15, 2026 at 8:53 pm

    Your question is answered in this question on the ggplot2 mailing list. Briefly,

    According to the documentation for predict.nls, it is unable to create
    standard errors for the predictions, so that has to be turned off in
    the stat_smooth call. .

    So, we need to turn off the standard errors:

    ggplot(df, aes(x=Mass, y=Solv)) +
      stat_smooth(method="nls", formula=y~i*x^z, se=FALSE, 
                  start=list(i=1,z=0.2)) +
      geom_point(shape=1) 
    

    Update 2019: for new versions of ggplot2, we need the start argument to nls to be passed like this:

    ggplot(df, aes(x = Mass, y = Solv)) +
      stat_smooth(method = "nls", 
                  se = FALSE,
                  method.args = list( 
                    formula = y ~ i*x^z, 
                    start = list(i=1, z=2)
                  )) +
      geom_point()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data set (below) with a power relationship. (Y =aX^b) The power
i have written a sample program.below: #include<iostream> #include<string> #include<set> using namespace std; int main()
I'm trying to fit Gaussian peaks to my density plots in R using nls
Using a CSS image sprite, I'm creating an 'interactive' image where hovering over certain
Using a populated Table Type as the source for a TSQL-Merge. I want to
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using SQL Server 2008 R2 we are looking for a way to select the
Using CI for the first time and i'm smashing my head with this seemingly
Using the Redis info command, I am able to get all the stats of
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the

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.