You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac系统下R语言plot.new()报错:attempt to plot on null device求助

Fixing "Error in plot.new() : attempt to plot on null device" in R on macOS

Hey there! Let's work through this plotting error you're hitting on your Mac. That Error in plot.new() : attempt to plot on null device typically crops up when R can't connect to a valid graphics window to draw your plot. It's a common issue on macOS, and there are a few straightforward fixes to try:

Quick Fixes to Try First

  • Reset your graphics device
    Sometimes the default Quartz graphics device gets stuck in a broken state. Run these commands to reset it:

    dev.off() # Close any hanging graphics devices
    dev.new() # Open a fresh graphics window
    plot(mlm.lob) # Attempt your plot again
    

    This clears out any leftover device connections and starts fresh, which often resolves the issue immediately.

  • Manually launch the Quartz device
    macOS relies on Quartz for R's graphics, and sometimes it doesn't initialize automatically. Explicitly start it before plotting:

    quartz() # Open a Quartz graphics window
    plot(mlm.lob)
    

If the Quick Fixes Don't Work

  • Check your RStudio pane (if using RStudio)
    Make sure the Plot pane in RStudio is visible and not minimized. If the pane is hidden, R might not have a place to render the plot. You can reset RStudio's layout via Tools > Global Options > Appearance > Reset RStudio Layout if needed.

  • Test in base R
    Try running your code in the base R app (the blue R icon in your Applications folder) instead of RStudio. If the plot works there, the issue is likely with RStudio—try updating RStudio to the latest version or reinstalling it.

  • Update R and macOS
    Outdated software can cause compatibility issues with graphics devices. Update R to the latest stable version, and make sure your macOS is up to date via System Settings > General > Software Update.

Why This Happens

The "null device" error means R doesn't have an active graphics window to draw into. On macOS, this can occur if the Quartz device fails to initialize, a previous plot window crashed and left the device in an invalid state, or your IDE (like RStudio) isn't properly configured to handle graphics output.

内容的提问来源于stack exchange,提问作者dylan roddy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 02:22:57