具有特定颜色的多曲面图的图例
Posted
技术标签:
【中文标题】具有特定颜色的多曲面图的图例【英文标题】:Legend for multi surface plot with specific colors 【发布时间】:2021-03-16 00:15:39 【问题描述】:以plot_ly
函数为例:
library("plotly")
z <- c(
c(8.83,8.89,8.81,8.87,8.9,8.87),
c(8.89,8.94,8.85,8.94,8.96,8.92),
c(8.84,8.9,8.82,8.92,8.93,8.91),
c(8.79,8.85,8.79,8.9,8.94,8.92),
c(8.79,8.88,8.81,8.9,8.95,8.92),
c(8.8,8.82,8.78,8.91,8.94,8.92),
c(8.75,8.78,8.77,8.91,8.95,8.92),
c(8.8,8.8,8.77,8.91,8.95,8.94),
c(8.74,8.81,8.76,8.93,8.98,8.99),
c(8.89,8.99,8.92,9.1,9.13,9.11),
c(8.97,8.97,8.91,9.09,9.11,9.11),
c(9.04,9.08,9.05,9.25,9.28,9.27),
c(9,9.01,9,9.2,9.23,9.2),
c(8.99,8.99,8.98,9.18,9.2,9.19),
c(8.93,8.97,8.97,9.18,9.2,9.18)
)
dim(z) <- c(15,6)
z2 <- z + 1
fig <- plot_ly(showscale = FALSE)
fig <- fig %>% add_surface(z = ~z, colorscale = list(c(0,1),c("rgb(107,184,255)","rgb(0,90,124)")))
fig <- fig %>% add_surface(z = ~z2, colorscale = list(c(0,1),c("rgb(255,107,184)","rgb(128,0,64)")))
如何在这个 3d 图中添加图例?
【问题讨论】:
如果您使用showscale = TRUE
代替,则有两个图例。那是你要的吗。否则,你能说得更具体点吗?
在这种情况下,出现的图例具有多种颜色,尽管我的每个表面都只是一种颜色。我想要一个传说,例如紫色是a
,黄色是b
。 @MLavoie
【参考方案1】:
你在找这个吗:
plot_ly(showscale = FALSE, showlegend = TRUE) %>%
add_surface(z = ~z, name = "Color Blue", colorscale = list(c(0,1),c("rgb(107,184,255)","rgb(0,90,124)"))) %>%
add_surface(z = ~z2, name = "Color Red", colorscale = list(c(0,1),c("rgb(255,107,184)","rgb(128,0,64)")))
【讨论】:
以上是关于具有特定颜色的多曲面图的图例的主要内容,如果未能解决你的问题,请参考以下文章