R语言 如何创建一个空图
在这篇文章中,我们将讨论如何在R语言中创建一个空图 。 在创建空图之前,我们首先讨论 什么是空图? 没有任何东西被绘制的图被称为空图,也被称为空白图。
R语言提供了plot()函数来绘制图表。
语法: plot(x,y,…)
参数 。
- x代表x轴
- y代表y轴
- …代表其他特征,如标题、颜色等。
现在我们讨论一些方法,通过这些方法我们可以创建一个空图。
方法一:使用 plot.new()
plot.new()函数将创建一个空图。这将给R带来一个信号,即一个新的绘图窗口被创建。因此,在这个函数的帮助下,一个空的绘图窗口被创建。
# plot function is used
# to draw the plot and
# new is used to make
# that plot new
plot.new()
输出 。
图1:空图
方法 2: 使用 plot.window( )
plot.window()函数将创建空图。这将给R带来一个信号,即一个新的绘图窗口被创建。因此,在这个函数的帮助下,一个空的绘图窗口被创建。但是,这个函数的参数对于设置绘图的极限是必要的。所以在这里,我们给出了两个轴的极限。
# plot is used to create the plot
# window is used to create the plot
# window and limits are set of the
# axis because limit arguments are
# necessary
plot.window(xlim = c(0 , 1), ylim = c( 5, 10))
输出 。
图2:空图
方法 3: 使用 plot( )
plot函数被用来创建一个图。因此,在这个方法中,我们首先使用plot函数创建绘图,然后删除绘图中的点或数据。为了删除绘制的数据,我们在plot函数中使用 type = “n “作为参数,这里使用 “n “来删除绘制的数据。
# plot function is used to plot
# the data type with "n" is used
# to remove the plotted data
plot(1, type = "n", xlab = "",
ylab = "", xlim = c(0, 5),
ylim = c(0, 5))
输出:
图3:移除数据后的曲线图