更改默认调色板会打开绘图 window - 有没有办法抑制它?
Changing default palette opens plotting window - is there a way to suppress it?
在 R 中更改调色板时:
palette(c("red", "green", "blue"))
一个空的 window 弹出窗口。阅读 help(palette)
但没有找到任何提及。有没有办法抑制这种行为并悄悄更改调色板?
palette
函数需要有一个适用的设备。如果您想避免看到交互式图形 window 出现,您需要在调用时打开一个文件设备。所以这就提出了问题:"What were you hoping to do with this?"
png()
palette(rainbow(6))
palette()
#[1] "red" "yellow" "green" "cyan" "blue" "magenta"
mypal <- palette()
dev.off() # no graphics device for that palette anymore
mypal # the state of that palette is now available.
#[1] "red" "yellow" "green" "cyan" "blue" "magenta"
此行为在 R 4.0.0 中已更改。
因此,如果您使用的是 R 4.0.0。或以上更改默认调色板颜色:
palette(c("red", "green", "blue"))
将不再打开空的图形设备 window。
在 R 中更改调色板时:
palette(c("red", "green", "blue"))
一个空的 window 弹出窗口。阅读 help(palette)
但没有找到任何提及。有没有办法抑制这种行为并悄悄更改调色板?
palette
函数需要有一个适用的设备。如果您想避免看到交互式图形 window 出现,您需要在调用时打开一个文件设备。所以这就提出了问题:"What were you hoping to do with this?"
png()
palette(rainbow(6))
palette()
#[1] "red" "yellow" "green" "cyan" "blue" "magenta"
mypal <- palette()
dev.off() # no graphics device for that palette anymore
mypal # the state of that palette is now available.
#[1] "red" "yellow" "green" "cyan" "blue" "magenta"
此行为在 R 4.0.0 中已更改。
因此,如果您使用的是 R 4.0.0。或以上更改默认调色板颜色:
palette(c("red", "green", "blue"))
将不再打开空的图形设备 window。