R:黑底白图元素

R: White plot elements on black background

在 R 中是否有一种简单的方法可以使绘图的所有元素(坐标轴、坐标轴标签、网格线、刻度线...)都变成黑色背景的白色?我看到了一些制作黑色背景的选项,但我不知道如何为情节元素重新着色。

我希望在一个相对复杂的情节上做到这一点。我的情节与使用 iris 数据集的 scatter3D 示例 here under "Change color by groups" 非常相似。我在下面包含了复制该图的必要代码。

library(plot3D)

# Set up data
data(iris)
x <- sep.l <- iris$Sepal.Length
y <- pet.l <- iris$Petal.Length
z <- sep.w <- iris$Sepal.Width

# Make 3d scatterplot with colors by category
scatter3D(x, y, z, bty = "g", pch = 18, 
      col.var = as.integer(iris$Species), 
      col = c("#1B9E77", "#D95F02", "#7570B3"),
      pch = 18, ticktype = "detailed",
      colkey = list(at = c(2, 3, 4), side = 1, 
      addlines = TRUE, length = 0.5, width = 0.5,
      labels = c("setosa", "versicolor", "virginica")) )
par(bg = 'black', fg = 'white') # set background to black, foreground white
scatter3D(
    x,
    y,
    z,
    bty = "u", ## 'u' seemed to look better than 'g'
    pch = 18,
    col.var = as.integer(iris$Species),
    col = c("#1B9E77", "#D95F02", "#7570B3"),
    pch = 18,
    ticktype = "detailed",
    colkey = list(
        at = c(2, 3, 4),
        side = 1,
        addlines = TRUE,
        length = 0.5,
        width = 0.5,
        labels = c("setosa", "versicolor", "virginica"),
        col.axis = "white",
        col.clab = "white"
    ),
    col.axis = "white",
    col.panel = "black",
    col.grid = "white"
)

我刚刚查看了 ?scatter3D 中的参数列表并将大部分颜色设置为白色 - 您也许可以删除其中的一些设置(或者找到更多您想要添加的设置)。例如,我没有检查在主调用和 colkey 列表中是否需要 col.axis = 'white'。也可能有更多的颜色可以设置(比如 col.ticks)。我建议在帮助页面中搜索 "col".