我可以在R中创建一个空的ggplot2图吗?

问题描述 投票:28回答:2

This question演示了如何将方程式放入ggplot2 qplot中。

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

我怎么能创建一个空的ggplot2图,以便我可以将标签添加到空画布?

r ggplot2
2个回答
37
投票
df <- data.frame()
ggplot(df) + geom_point() + xlim(0, 10) + ylim(0, 100)

根据@ ilya的建议,geom_blank非常适合您已有数据并且可以根据它设置比例,而不是明确定义它。

ggplot(mtcars, aes(x = wt, y = mpg)) + geom_blank()

4
投票

如果要创建完全空的图,请使用以下代码:

ggplot() + theme_void()

无需定义数据框。

© www.soinside.com 2019 - 2024. All rights reserved.