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?
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.
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 .
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With