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

The Archive Base Latest Questions

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

I write many packages where the generic plot is a ggplot2 . A ggplot

  • 0

I write many packages where the generic plot is a ggplot2. A ggplot call, unlike other R function calls, is layered so one could end up with several options (separated by + signs) to get a plot looking just right. However, I don’t want someone to suffer through my pre-defined options and would like them to be able to customize it without re-writing my function from scratch. How do I accomplish this?

With a traditional function, I could use the three dot operator to pass optional arguments. This seems harder with a ggplot.

Reproducible example

f <- function(df) {
 custom_plot <-  ggplot(df, aes(mpg, disp, color = gear)) + 
geom_point(size = 3) +  
theme(panel.background = element_blank(), panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(), panel.border = element_blank(),
        axis.line = element_line(colour = "black"))
        return(custom_plot)
}

To generate a plot

f(mtcars)

produces this:

A test plot

How do I generalize this function such that someone could pass additional or different options to this plot (especially in cases where it is the generic plot)?

If my function were defined as:

f <- function(df, ...)

How would I pass those in to my ggplot 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-15T20:38:15+00:00Added an answer on June 15, 2026 at 8:38 pm

    The plots returned by your functions should be modifiable for anyone who knows ggplot- unless you can think of specific cases that can’t be fixed by using +, a better solution might be to do as little theming and customization as possible, and let people add to the plots themselves.

    All of these customizations work fine, for example:

    mtplot <- f(mtcars)
    mtplot + theme_bw()
    mtplot + scale_colour_gradientn(colours=c("red", "purple"))
    mtplot + labs(title="Add a title!")
    mtplot + geom_point(size=5)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There're many ways to write an HTTP-status header: HTTP/1.1 404 Not Found Status: 404
There are now so many ways to write windows apps, win32, MFC, ATL, .NET,
I normally write code with tabs but many python libraries use spaces. Is there
I've been teaching myself to write exploits and shellcode recently and many of the
I'm trying to write a script to pull the word count of many files
My job is to write plsql code in PLSQL Developer 9.0.6.1665. There are many
How can i write this correctly ? I want to check how many days
Summary A parent can have many children. How do you write a service such
I'm starting to write more and more web applications for work. Many of these
Occasionally , we have to write methods that receive many many arguments , for

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.