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. :)

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).

Similar Questions

I am trying to do some density plots in R. I originally used density plot but I changed to the density plot in ggplot2 because I visually prefer ggplot2. So I did a density plot using the density plot

I am plotting line charts showing the change in price over time for multiple instruments, using ggplot2. I have succeeded in getting multiple lines on the plot and adding values showing the most recen

I want to plot the power of F-test with ggplot2 and MWE is below with the graph output: library(ggplot2) df1 <- 3 df2 <- 8 Alpha <- 0.05 df <- data.frame(X = seq(from = 0, to = 10, length

I'm struggling to graph a boxplot from a dataframe. I have a dataframe df which contains 3 columns: df$A , df$B, df$C. I want to have df$C in the X-axis and plot df$A and df$B as boxplot on the Y-axis

Is it possible to filter out subsets of the data that have small numbers of observations within a ggplot2 call? For example, take the following plot: qplot(price,data=diamonds,geom=density,colour=cu

I plot Iris data with ggplot2. It seems ggplot2 will standardized the data to (0.1) interval automatically. How can I plot the data without any standardized manipulation? library(ggplot2) p <- ggpc

What's the best way to unit test large data sets? Some legacy code that I'm maintaining has structures of a hundred members or more; other parts of the code that we're working on create or analyze dat

I have a time series with multiple days of data. In between each day there's one period with no data points. How can I omit these periods when plotting the time series using ggplot2? An artificial exa

I'd like to plot a bar graph showing frequency of a string in ggplot. The input file (t1. txt) looks like: do 4 re 2 mi 5 and my current r script is: library(ggplot2) t1<-read.table(t1.txt,hea

I am trying to create a ggplot2 facet wrapped by plot type. I've used grid.arrange but I'm trying to maximise the plot area, using the grid.arrange I loose area due to the repeating of the y axis and

I'm trying to produce a png chart using ggplot2 and ggsave (with Cairo) in R. I'm having an issue with customising the theme to remove margins. Currently I'm using: ... + theme(plot.margin=unit(c(0,0,

I created a density plot with ggplot from a dataframe with 3 variables. One density line is dotted, but the legend shows a solid line for this line. The data looks like this: > head(df) R1 R2 R3 1

I have a question about legends in ggplot2. I managed to plot three lines in the same graph and want to add a legend with the three colors used. This is the code used library(ggplot2) require(RCurl) l

I have problems plotting a raster with factor values using ggplot2. library(ggplot2) library(raster) first, load raster data f <- system.file(external/test.grd, package=raster) r <- raster

I'm trying to plot the connecting lines for different sets of coordinates found in a file with the following format:(both coordinates have the same Y-value but different X-values) Y1 X11 X12 Y2 X21 X2

I am trying to create an interaction plot, and R is throwing the error geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?, which I don't understand why.

I'm looking for an answer to a very specific problem. I found the way to superimpose a function over a plot in ggplot2 at their page: http://docs.ggplot2.org/current/stat_function.html But in my case

I am doing experiments with different operational amplifier circuits and I need to plot my measured results onto a graph. I have two data sets: freq1 = [.1 .2 .5 .7 1 3 4 6 10 20 35 45 60 75 90 100];

I have the following code which seems to work well when I just have it as below p<-ggplot(data=x.all.ER, aes(x=Year, y=value, fill = (factor(x.all.ER$Strategy))))+ geom_bar(stat = 'identity',posit

I can force ggplot2 scatter plot to be square shaped with the same x and y scaling using xlim() and ylim(), but it needs manual calculation of the limits. Is there any more convenient way of doing it?

I find this variable a little confusing, for example, from the docs: require(ggplot2) require(reshape2) volcano3d <- melt(volcano) names(volcano3d) <- c(x, y, z) v <- ggplot(volcano3d,

Suppose I have a data set called data, and is generated through: library(reshape2) # Reshape data, needed in command melt library(ggplot2) # apply ggplot density <-rep (0.05, each=800) tau <

I'm new to open source stacks and have been playing with hibernate/jpa/jdbc and memcache. I have a large data set per jdbc query and possibly will have a number these large data sets where I eventuall

I'd like to try to recreate this graphic for repeated measures: parrellel dot plot in R using ggplot2. I'm not so concerned about the p-value text. As a dataset, I'm playing around with the epilepsy d

How do I plot a choropleth or thematic map using ggplot2 from a KML data source? Example KML: https://dl.dropbox.com/u/1156404/nhs_pct.kml Example data: https://dl.dropbox.com/u/1156404/nhs_dent_stat_

I know how to plot with R's default plotting function. How do I do the same thing as the following R-code in ggplot2? double <- function(x){ return(x^2) } triple <- function(x){ return(x^3) } x

I have a data frame in R, and I'd like to add dummy variables in order to plot different items different colors. My data frame, df <-, is something like this: UID CategoryA count 1 AAA 2 2 AAA 2 3

This question already has an answer here: Add legend to ggplot2 line plot 2 answers Have a dataset, df, with >10000 rows. The first 30 rows are: >df ms_estimate moso_estimate sig 1554 6.5

I'd like to plot 2 different charts side by side with a common y-axis using ggplot2: p1) an area rectangle graph using geom_rect() p2) a density plot using geom_density() I've come close by using

Instead of the normal plot function I am using ggplot2 to create NMDS plots. I would like to display groups in the NMDS plot using the function ordiellipse() from the vegan package. Example data: lib

I'm trying to plot a set of data with ggplot2. The data are in two categories. I would like to plot them together, with a single linear regression line. However, I would like to have each of the two g

I'd like to place an annotation at the center of a several ggplot objects. I've researched and found a few similar questions such as here: Relative positioning of geom_text in ggplot2? So far, the on

I have the following data to produce a bar chart in ggplot2 (R) Bin Plr groupname data ci 3 1% solution 1002.97 6.98322 10 1% solution 1001.7 1.25921 30 1% solution 1176.47 12.1888 3 1% w/o solution 1

data file: http://ubuntuone.com/3x5z4kFEUcVUB8KXYjICpD Plotting the above data like this clips some of it: tc = read.table('tertiary-tc.csv', header=T, sep=',') library(ggplot2) old <- theme_set(th

I am using scale_colour_manual to specify the possible keys in the legend. However, if I use stat_function to plot custom function, the legend is missing. Any ideas why this happen? library(ggplot2) M

Say I have the following data: require(ggplot2) set.seed(123) data <- data.frame(x = sample(1:20, 100, replace = TRUE)) I want to create a dot plot of data$x, so this is what I do: ggplot(data, ae

I have a large amount of data to plot, and I'm trying to use gnuplot. The data is a sorted array of around 80000 elements. By simply using plot myData.txt using 1:2 with linespoints linetype 1 poin

I am trying to use a polar plot to represent frequencies according to a circular angle/direction (0-360 degrees). For some reason I am having problems trying to define the scale in the plot to represe

I want to plot y=log(1+x) and y=x in the range [-0.25, 0.25]. Here is my code so far - library(ggplot2) log1plusx <- function(x) log(1+x) self <- function(x) x ggplot(data.frame(x=c(-0.25, 0.25

How can I plot the relative proportions of two groups using a fill aesthetic in ggplot2? I am asking this question here because several other answers on this topic seem incorrect (ex1, ex2, and ex3),

I have a data.frame (d) that looks like this: x y ylo yhi A 0.21 0.01 0.41 D 0.11 -0.09 0.31 M 0.13 -0.07 0.33 N 0.14 -0.06 0.34 F 0.17 -0.03 0.37 I plotted a forest plot using the following code

I am plotting a number of data sets using ggplot2 in R. To make the plots easier to compare, I am setting the limits of the y-scale, but, it turns out, nothing is plotted above the 'natural top' of th

I'm trying to plot several sets of ordered pairs on the same plot, using R. I don't need a line between them, because that's already taken care of by a simple linear regression. Here's some sample cod

I'm trying to plot densities on both sides of the x axis - trying to visualize reads mapping to both strands of a genomic region. I have two problems : I want to use ggplot2 but I don't know how to

I have a very large amount of data that needs plotting which is stored in 3 columns as xyz data. I need to convert the column data into a grid so I can easily plot it with contourf in matplotlib and I

when i try to add (data.table/ggplot2)code in slidify, i got error. Here is my code in slidify: ## data.table ```{r} library(data.table) DT = data.table(x = 1:5, y=6:10) setkey(DT, x) DT[J(1)] # Error

I am using plot() for over 1 mln data points and it turns out to be very slow. Is there any way to improve the speed including programming and hardware solutions (more RAM, graphic card...)? Where are

I recently upgraded to ggplot2 0.9.0 from version 0.8.9, and now I'm getting that my plot legends only show the factor levels used in the plot (it omits the unused ones). Before it'd include all facto

I am attempting produce a scatter plot using the ggplot2 library. My data frame (called scatterPlotData) is in this form: 115 2.3 120 1.6 . . . 132 4.3 (The ... signifies many other similar values).

I am plotting data in a typical MATLAB scatterplot format. Ordinarily when plotting multiple datasets, I would use the command 'hold on;', and then plot each of the data, followed by this to get my le