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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:34:28+00:00 2026-05-30T16:34:28+00:00

I would like my plot axis title to include among the text a function

  • 0

I would like my plot axis title to include among the text a function that performs a calculation on some data.

For example here are some data

a<-data.frame(time="1000",x=rnorm(10,12,3))
b<-data.frame(time="2000",x=rnorm(50,13,4))
c<-data.frame(time="3500",x=rnorm(50,12,4))
d<-data.frame(time="5000",x=rnorm(7,14,5))
e<-data.frame(time="7000",x=rnorm(20,10,3))
f<-data.frame(time="7500",x=rnorm(15,11,3))
g<-data.frame(time="9000",x=rnorm(15,10,5))
h<-data.frame(time="9500",x=rnorm(35,30,2))
i<-data.frame(time="10000",x=rnorm(30,28,4))
a2i<-rbind(a,b,c,d,e,f,g,h,i) 

library(ggplot2)
a2i$time<-as.numeric(levels(a2i$time))[a2i$time] 
ggplot(a2i,aes(time,x))+stat_smooth()+geom_point()+
# now let's try to put on a label with a function
# mixed in with the text
#
xlab("Time (total number of observations = paste(length(a2i$x))))")
#
# but that's no good, the function is not executed, just printed
# How can I get a function to work in the axis title?

enter image description here

I’d like to keep “time” in the title as a constant, but have the function return different results as the data change. And get the parentheses in there as well.

I’ve had a go with paste() and expression(), but I’m not having much luck. Any tips would be greatly appreciated.

  • 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-05-30T16:34:29+00:00Added an answer on May 30, 2026 at 4:34 pm

    You should first build a string that contains the test you want,
    with paste or sprintf, and then feed it to xlab.
    In particular, paste should not be inside the string.

    xlab( paste( 
      "Time (total number of observations = ", 
      length(a2i$x), 
      ")", 
      sep="" 
    ) )
    
    # Equivalently
    xlab( sprintf( 
      "Time (total number of observations = %s)", 
      length(a2i$x) 
    ) )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to plot this kind of data: X axis: dates Y axis:
I would like to plot two sets of values on a bar chart, that
I would like to plot the shifted logistic function as shown from Wolfram Alpha
On a generic plot, with time on the x-axis, I would like to highlight
I have an axis on a 3D plot which I would like to plot
I am trying to use the plot function in R. I would like to
Suppose one would like to plot 2 sets of data with unequal number of
I'm trying to use hexbin to plot some data on a square axis. I
I have chart.png with data in it that I would like to put a
I would like to plot a vertical line (I'd prefer any orientation, but I'd

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.