如何绘制空图?
我需要做一个空的情节。这是我能想到的最好的办法了。
plot(0, xaxt = 'n', yaxt = 'n', bty = 'n', pch = '', ylab = '', xlab = '')
有更简单的解决方案吗?
PS:完全空的,没有轴等。
I need to make an empty plot. This is the best could I come up with.
plot(0, xaxt = 'n', yaxt = 'n', bty = 'n', pch = '', ylab = '', xlab = '')
Any simpler solutions?
P.S.: completely empty, no axis etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
怎么样:
How about something like:
我建议有人需要制作空图,以便稍后在其上添加一些图形。因此,
您可以使用指定图形的轴限制。
I suggest that someone needs to make empty plot in order to add some graphics on it later. So, using
you can specify the axes limits of your graphic.
以下不会在图中绘制任何内容,并且它将保持为空。
这将产生:
当您想在
for
循环或类似内容中添加线条或点时,这非常有用。只需记住根据要绘制的数据更改xlim
和ylim
值即可。附注:
这也可用于箱线图、小提琴图和群体图。对于那些记得将
add = TRUE
添加到其绘图函数中,并指定at =
来指定要在哪个数字上绘制它们(默认为 x 轴,除非您设置了这些函数中的horz = TRUE
如果您想触发新的绘图,例如当您使用
layout()
时,最好使用plot.例如,在下面,我们将在第一行的两侧添加空图以添加一些填充:
在此图中,我手动注释了区域以阐明我的意思:
以下是您实际得到的内容:
The following does not plot anything in the plot and it will remain empty.
Which will produce:
This is useful when you want to add lines or dots afterwards within a
for
loop or something similar. Just remember to change thexlim
andylim
values based on the data you want to plot.As a side note:
This can also be used for Boxplot, Violin plots and swarm plots. for those remember to add
add = TRUE
to their plotting function and also specifyat =
to specify on which number you want to plot them (default is x axis unless you have sethorz = TRUE
in these functions.If you want to trigger a new plot, for example when you are using
layout()
, you are better off withplot.new()
. For example in the following we are adding empty plots to either side of the first row to add some padding:In this plot I have manually annotated the regions to clarify what I mean:
And the following is what you actually get:
这比您原来的解决方案稍微简单一些:
This is marginally simpler than your original solution:
Adam,按照您上面的评论(“我希望空图作为多图(mfrow)图中的填充物。”),您真正想要的是 mfg 选项
- 它控制您想要放置下一个图的位置。例如,要将一个图放在 3x3 多重图的中间,请执行以下操作
Adam, following your comment above ("I wanted the empty plot to serve as filler in a multiplot (mfrow) plot."), what you actually want is the mfg option
- which controls where you want to put the next plot. For instance, to put a plot in the middle of a 3x3 multiplot, do
你需要一个新的绘图窗口,还需要一个坐标系,所以你需要
plot.new()
和plot.window()
,然后你就可以开始添加图形元素:示例图
You need a new plot window, and also a coordinate system, so you need
plot.new()
andplot.window()
, then you can start to add graph elements:example plot
您的解决方案有一个
plot.new()
没有的兴趣:在您“绘制”的空图中,您可以使用text(x = .. ., y = ..., your_text)
。There is an interest in your solution that
plot.new()
hasn't though: in the empty plot you "draw" you can write text at specified coordinates withtext(x = ..., y = ..., your_text)
.带有一些已设置位置的文本的空图。
An empty plot with some texts which are set position.
如果有人正在寻找 ggplot2 解决方案,您可以使用
cowplot
或patchwork
包由 reprex 包于 2019 年 3 月 17 日创建(v0.2.1.9000 )
If anyone is looking for a
ggplot2
solution, you can use eithercowplot
orpatchwork
packagesCreated on 2019-03-17 by the reprex package (v0.2.1.9000)
另一个简单的 ggplot2 选项是使用 geom_blank ,如下所示:
< img src="https://i.sstatic.net/UxDqf.png" alt="">
创建于 2022 年 8 月 21 日,使用 reprex v2.0.2
如您所见,该图是空白的。
Another simple
ggplot2
option is using geom_blank like this:Created on 2022-08-21 with reprex v2.0.2
As you can see the plot is blank.