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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:41:06+00:00 2026-05-26T04:41:06+00:00

Rather than ask how to plot big data sets, I want to wrap plot

  • 0

Rather than ask how to plot big data sets, I want to wrap plot so that code that produces a lot of plots doesn’t get hammered when it is plotting a large object. How can I wrap plot with a very simple manner so that all of its functionality is preserved, but first tests to determine whether or not the object being passed is too large?

This code works for very vanilla calls to plot, but it’s missing the same generality as plot (see below).

myPlot <- function(x, ...){
    isBad <- any( (length(x) > 10^6) || (object.size(x) > 8*10^6) || (nrow(x) > 10^6) )
    if(is.na(isBad)){isBad = FALSE}
    if(isBad){
        stop("No plots for you!")
    }
    return(plot(x, ...))
}

x = rnorm(1000)
x = rnorm(10^6 + 1)

myPlot(x)

An example where this fails:

x = rnorm(1000)
y = rnorm(1000)
plot(y ~ x)
myPlot(y ~ x)

Is there some easy way to wrap plot to enable this checking of the data to be plotted, while still passing through all of the arguments? If not, then how about ggplot2? I’m an equal opportunity non-plotter. (In the cases where the dataset is large, I will use hexbin, sub-sampling, density plots, etc., but that’s not the focus here.)


Note 1: When testing ideas, I recommend testing for size > 100 (or set a variable, e.g. myThreshold <- 1000), rather than versus a size of > 1M – otherwise there will be a lot of pain in hitting the slow plotting. 🙂

  • 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-26T04:41:06+00:00Added an answer on May 26, 2026 at 4:41 am

    The problem you have is that as currently coded, myplot() assumes x is a data object, but then you try to pass it a formula. R’s plot() achieves this via methods – when x is a formula, the plot.formula() method gets dispatched to instead of the basic plot.default() method.

    You need to do the same:

    myplot <- function(x, ...)
        UseMethod("myplot")
    
    myplot.default <- function(x, ....) {
        isBad <- any((length(x) > 10^6) || (object.size(x) > 8*10^6) || 
                        (nrow(x) > 10^6))
        if(is.na(isBad)){isBad = FALSE}
        if(isBad){
            stop("No plots for you!")
        }
        invisible(plot(x, ...))
    }
    
    myplot.formula <- function(x, ...) {
        ## code here to process the formula into a data object for plotting
        ....
        myplot.default(processed_x, ...)
    }
    

    You can steal code from plot.formula() to use in the code needed to process x into an object. Alternatively, you can roll your own following the standard non-standard evaluation rules (PDF).

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

Sidebar

Related Questions

Rather than just grabbing the user's friends' emails, I want to show their list
Rather than have everything in one big dialog, I'm looking at being able to
Has anyone used Lucene.NET rather than using the full text search that comes with
really new to linux scripting so i figured i would ask rather than waste
I have a block of code that works and I wanted to ask what
I want to ask a question about the html code. I have a input
I have a process that is doing some heavy maths with gl rather than
Rather than population said DOM object with an external page such as HTML CFM
Rather than scraping a Ruby version of this algorithm off the net I wanted
rather than using a textnode to show content im trying to figure out how

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.