在使用 R 语言进行绘图时,你可能会遇到 'Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet' 的错误。

这个错误通常是因为在调用 plot() 或其他绘图函数之前,没有先调用 plot.new() 函数来创建新的绘图区域。

解决方法如下:

  1. 在绘图之前调用 plot.new() 函数:

    plot.new()
    plot(x, y, ...) # 你的绘图代码
    
  2. 使用其他绘图工具,例如 ggplot2:

    ggplot2 是一个强大的 R 包,可以创建更加灵活和美观的图形。它不需要手动调用 plot.new(),因为它会自动管理绘图区域。

    library(ggplot2)
    ggplot(data, aes(x = x, y = y)) + geom_point() # 使用 ggplot2 绘图
    

请注意,如果你使用的是 par(mfrow = c(m, n)) 等函数来分割绘图区域,则每个绘图区域都需要调用 plot.new() 函数。

R语言绘图错误:'plot.new has not been called yet' 的解决方法

原文地址: https://www.cveoy.top/t/topic/omrR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录