R语言如何修复:error in plot.new() : figure margins too large

R语言如何修复:error in plot.new() : figure margins too large

在这篇文章中,我们将讨论如何在R编程语言的plot.new()函数中修复 “图边距过大 “的错误。

人们在R语言中可能面临的错误是。

Error in plot.new() : figure margins too large
Bash

当Rstudio的绘图面板对于我们试图创建的绘图的尺寸较小时,R编译器会产生这个错误。

当这个错误可能发生时

考虑到想用R语言中的plot()函数来创建一个图,这个函数的语法如下。

语法

plot(start : end)

参数

  • start。起始点(1为(x,y)=(1,1)等)。
  • end。结束点 ( 5 for (x, y) = (5, 5) 等等)

返回类型

在x轴和y轴上按顺序画点。

例子

# Draw a plot
plot(1:40)
Bash

输出

R语言如何修复:error in plot.new: figure margins too large

R编译器产生错误(你可以看到右边的面板窗口相当小)。

如何修复这个错误

在R中,有三种方法可以修复这个错误。

方法 1:增加面板的大小

一种方法是增加面板的尺寸,使其能够容纳整个绘图的尺寸。

# Draw a plot
plot(1:40)
Bash

输出

R语言如何修复:error in plot.new: figure margins too large

方法 2:使用par()函数

R中的par()函数是用来设置绘图的边距的。这个函数的语法如下。

语法

par(mfrow)

参数

mfrow。 它代表一个包含网格的行和列值的向量

默认情况下,绘图具有以下边距。

  • 顶部:4.1和底部。5.1
  • 左边:4.1,右边:2.1

我们需要明确地设置绘图的边距为。

# Set plot margins
par(mar = c(1, 1, 1, 1))
  
# Create the plot
plot(1 : 40)
Bash

输出

R语言如何修复:error in plot.new: figure margins too large

由于我们减少了边距以适应所创建的绘图,因此该绘图很容易在面板窗口中投影。

方法3:关闭绘图设备

如果前面两种方法都无法解决错误,那么您可以通过以下命令关闭当前的绘图设备。

# Turn off the device
dev.off()
Bash

输出

R语言如何修复:error in plot.new: figure margins too large

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册