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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:58:15+00:00 2026-06-09T09:58:15+00:00

I have a plot and would like to add some regression statistics (e.g. F,

  • 0

I have a plot and would like to add some regression statistics (e.g. F, R2, p) in the plot area. I am familiar with text(), but have been unable to find a comprehensive source of information with examples on how to build text strings with mathematical symbols, sub-and superscripts, etc. Any sources with detailed examples greatly appreciated.

For example, I have a simple linear regression that I would like to extract the stats from and add them to my plot. For example

reg1 <- lm(WW1 ~ PC1, data = WW_Data)

I would like to have something like F1,69 = 14.38, p = < 0.001, R2adj = 0.16 where “1,69” and “adj” is subscript, and “p” is in italics.

EDIT:

Thanks to @Backlin for a great answer to my question. I have expanded on it a bit so that if you get a highly significant p-value the code substitutes “< 0.001” and rounded all the statistics to 2 decimal places, except the p-value which I have rounded to 3.

WW_Data <- data.frame(WW1=rnorm(10), PC1=1:10)
reg1 <- lm(WW1~PC1, WW_Data)
sreg1 <- summary(reg1)
plot(0, 0)
text(0, .2, eval(substitute(
    expression(list(F[list(fn,fd)]==fv,italic(p)==pv,R[adj]^2==R2adj)),
        list(fv = round(sreg1$fstatistic[1],2), fn = sreg1$fstatistic[2],
             fd = sreg1$fstatistic[3], pv = ifelse(sreg1$coefficients["PC1",4] < 0.001, "< 0.001",round(sreg1$coefficients["PC1",4],3)),
             R2adj = round(sreg1$adj.r.squared,2)))))
  • 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-09T09:58:17+00:00Added an answer on June 9, 2026 at 9:58 am

    I have struggled a lot with it myself too, but it is actually all in ?plotmath. Your expression would be the following,

    # Fixed expression
    text(x, y, expression(list(F[list(1,69)]==14.38,italic(p)<0.001,R[adj]^2==0.16)))
    
    # Using the values of your lm
    sreg1 <- summary(reg1)
    text(x, y, eval(substitute(
        expression(list(F[list(fn,fd)]==fv,italic(p)==pv,R[adj]^2==R2adj)),
            list(fv = sreg1$fstatistic[1], fn = sreg1$fstatistic[2],
                 fd = sreg1$fstatistic[3], pv = sreg1$coefficients["PC1",4],
                 R2adj = sreg1$adj.r.squared))))
    

    Here’s a dummy example of what it looks like.

    WW_Data <- data.frame(WW1=rnorm(10), PC1=1:10)
    reg1 <- lm(WW1~PC1, WW_Data)
    sreg1 <- summary(reg1)
    plot(0, 0)
    text(0, .2, eval(...)) # The expression above
    

    enter image description here

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

Sidebar

Related Questions

I have a density plot and I would like to add some summary information
I have a large real 1-d data set called r. I would like plot:
I have several file with the following format: lat,lon,value. I would like to plot
I would like to add an image to a plot. I can sucessfully place
I would like to add an image to a plot. I can sucessfully place
I managed to plot my data and would like to add a background image
I have three data sets of different lengths and I would like to plot
I would like to have a small function displaying basic data statistics for eachnumeric
I have a plot in a tkinter.Toplevel window and I would like to have
I like add text and some images to a div using jquery. I can

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.