Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create an empty ggplot2 plot in R?

Tags:

r

ggplot2

This question demonstrates how to put an equation into a ggplot2 qplot.

q <- qplot(cty, hwy, data = mpg, colour = displ) q + xlab(expression(beta +frac(miles, gallon))) 

How could I create an empty ggplot2 plot so that I could add the label to an empty canvas?

like image 591
Jim Avatar asked Sep 20 '12 18:09

Jim


People also ask

How do I create a blank plot in R?

Method 1: Using plot.new() The plot. new() function will create the empty plot. This will give a signal to R that a new window of the plot is created. So, an empty window of the plot is created with the help of this function.

Can you use Ggplot without a Dataframe?

Using ggplot2 with a matrixggplot only works with data frames, so we need to convert this matrix into data frame form, with one measurement in each row. We can convert to this “long” form with the melt function in the library reshape2 .

Why is Ggplot blank?

A blank ggplot is drawn. Even though the x and y are specified, there are no points or lines in it. This is because, ggplot doesn't assume that you meant a scatterplot or a line chart to be drawn.


1 Answers

df <- data.frame() ggplot(df) + geom_point() + xlim(0, 10) + ylim(0, 100) 

and based on @ilya's recommendation, geom_blank is perfect for when you already have data and can just set the scales based on that rather than define it explicitly.

ggplot(mtcars, aes(x = wt, y = mpg)) + geom_blank() 
like image 103
Maiasaura Avatar answered Oct 03 '22 01:10

Maiasaura