当我保存 ggplot 图像时,theme_minimal黑白值在照片负片效果中反转。如果我不使用主题,则不会发生这种情况,使用 theme_bw 也不会发生这种情况。.pdf保存到或 时也不会发生这种情况.png。我已经测试过,在 RStudio、R GUI 或通过终端运行时会发生这种情况。我在 Mac OS 10.15.7 上运行 R 版本 4.0.2。
我将非常感谢任何对此进行调试的见解。在多次完整系统重新启动后,该行为已持续数周。
library(ggplot2)
ggplot(diamonds, aes(x = cut, y = clarity)) +
geom_point() +
theme_minimal()
ggsave("test_minimal.jpg")
Run Code Online (Sandbox Code Playgroud)

小智 10
似乎“theme_minimal”默认为 jpg 文件的黑色背景(pdf 和 png 都很好,我使用的是 Windows 10)。@stefan 在上面的评论中提出了两种方法来克服这个问题。我没有看到,又去寻找。所以在这里发布完整的解决方案:
library(ggplot2)
ggplot(diamonds, aes(x = cut, y = clarity)) +
geom_point() +
theme_minimal()
ggsave("test_minimal.jpg",bg="white")
Run Code Online (Sandbox Code Playgroud)