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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:02:20+00:00 2026-05-23T10:02:20+00:00

I am very new to R and just learnt to write simple functions. Can

  • 0

I am very new to R and just learnt to write simple functions. Can someone help me understand why the following function does not work.

fboxplot <- function(mydataframe, varx, vary)
  {
    p <- ggplot(data=mydataframe, aes(x=varx, y=vary))
    p + geom_boxplot()
  }

col1 = factor(rep(1:3, 3))
col2 = rnorm(9)
col3 = c(rep(10,5), rep(20,4))
df = data.frame(col1 = col1, col2 = col2, col3 = col3)

Now, if I call the fboxplot function

fboxplot(df, col1, col2)

I get the error Error in eval(expr, envir, enclos): object varx not found. I also tried

fboxplot(df, varx = col1, vary = col2)

That gives the same error. Where am I going wrong?

Thanks for your help.

  • 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-23T10:02:20+00:00Added an answer on May 23, 2026 at 10:02 am

    The aes function in ggplot2 uses names like library() does, i.e. it takes the name of the argument as the argument. If this is an object, it does not evaluate it but takes the name instead. Here it takes varx as the argument and not what varx evaluates too.

    It works if you use aes_string() instead and use characters as arguments in the fboxplot() call:

    fboxplot <- function(mydataframe, varx, vary)
      {
        p <- ggplot(data=mydataframe, aes_string(x=varx, y=vary))
        p + geom_boxplot()
      }
    
    col1 = factor(rep(1:3, 3))
    col2 = rnorm(9)
    col3 = c(rep(10,5), rep(20,4))
    df = data.frame(col1 = col1, col2 = col2, col3 = col3)
    
    fboxplot(df, "col1", "col2")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I very new to programming and I have a simple problem that I just
I'm very new to WPF, so I've just started making a very simple Memory
I'm very new to Python and just crawling my way through it to accomplish
I'm very new to MVC, and just building my first site, using NerdDinner as
I've just performed a new installation of the very latest (Fall, 2008) version of
Very often, I just create a new folder and test things out in there.
I am new to NHibernate and have just started right now. I have very
Im very new to SQL but need to write a query to do the
Warning - I am very new to NHibernate. I know this question seems simple
I'm very new to programming and I'm just starting to learn VBA with excel.

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.