预设颜色

library(ggplot2)
library(plotly)

Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':

    last_plot
The following object is masked from 'package:stats':

    filter
The following object is masked from 'package:graphics':

    layout
colors <- data.frame(
  x = rep(c(seq(1, 26), seq(26, 1, by = -1)),
          length.out = length(colors())
          ),
  y = rep(seq(1, 26),each = 26)[1:length(colors())], 
  color = colors()
  )

p <- ggplot(colors, aes(x, y, fill = color)) +
  geom_raster() +
  scale_fill_identity() +
  theme_void()

ggplotly(p, tooltip = "color") |> 
  layout(showlegend = FALSE)
par(mar = c(0, 0, 0, 0), bty = "n")
plot(c(0, 98), c(0, 73), type = "n", xlab = "", ylab = "")
for (i in 0:8) {
  rect(i * 11, 73:1, i * 11 + 10, 72:0, col = colors()[1:73 + i * 73])
  text(i * 11 + 5, 73:1 - 0.5, labels = colors()[1:73 + i * 73], cex = 0.7)
}