我正在尝试针对四种物种绘制蒸腾量相对于采样日的回归线,但是我正在使用指定彩色线的代码。我想使用以下代码,但要使用黑色,白色和灰色。
plotly_interaction <- function(data, x, y, category, colors = col2rgb(viridis(nlevels(as.factor(data[[category]])))), ...) {
require(plotly)
require(viridis)
require(broom)
groups <- unique(data[[category]])
p <- plot_ly(...)
for (i in 1:length(groups)) {
groupData = data[which(data[[category]]==groups[[i]]), ]
p <- add_lines(p, data = groupData,
y = fitted(lm(data = groupData, groupData[[y]] ~ groupData[[x]])),
x = groupData[[x]],
line = list(color = paste('rgb', '(', paste(colors[, i], collapse = ", "), ')')),
name = groups[[i]],
showlegend = FALSE)
p <- add_ribbons(p, data = augment(lm(data = groupData, groupData[[y]] ~ groupData[[x]])),
y = groupData[[y]],
x = groupData[[x]],
ymin = ~.fitted - 1.96 * .se.fit,
ymax = ~.fitted + 1.96 * .se.fit,
line = list(color = paste('rgb','(', paste(colors[, i], collapse = ", "), ', 0.05)')),
fillcolor = paste('rgba', '(', paste(colors[, i], collapse = ", "), ', 0.1)'),
showlegend = FALSE)
p <- add_markers(p, data = groupData,
x = groupData[[x]],
y = groupData[[y]],
symbol = groupData[[category]],
marker = list(color=paste('rgb','(', paste(colors[, i], collapse = ", "))))
}
p <- layout(p, xaxis = list(title = x), yaxis = list(title = y))
return(p)
}