1

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

我希望在一个相对复杂的情节上做到这一点。我的情节与使用 iris 数据集的“按组更改颜色”下的 scatter3D 示例非常相似。我已经包含了必要的代码来复制下面的那个图。

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")) )
4

1 回答 1

2
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并将大部分颜色设置为白色 - 您可能可以删除其中一些设置(或找到更多您想要添加的设置)。例如,我没有检查col.axis = 'white'主调用和colkey列表中是否有必要。还可以设置更多颜色(如col.ticks)。我建议在帮助页面中搜索“col”。

于 2016-08-11T20:57:50.930 回答