Plotly layer control:如何在形状前面添加文本
我正在使用plotly显示一些形状,并在其上添加一些注释(文本)。但是,我不知道如何控制图层顺序,以便在plotly中打印对象,并且文本始终位于形状后面(我在plotly R API文档中未找到任何示例) 下面是一个可复制的示例:Plotly layer control:如何在形状前面添加文本,r,plotly,R,Plotly,我正在使用plotly显示一些形状,并在其上添加一些注释(文本)。但是,我不知道如何控制图层顺序,以便在plotly中打印对象,并且文本始终位于形状后面(我在plotly R API文档中未找到任何示例) 下面是一个可复制的示例: library("plotly") shapes <- list( list(type = "rect", fillcolor = "red", line = list(color = "white"), x0 = 0.0, x
library("plotly")
shapes <- list(
list(type = "rect",
fillcolor = "red", line = list(color = "white"),
x0 = 0.0, x1 = 0.5, xref = "x",
y0 = 0.0, y1 = 1.0, yref = "y",
opacity = 0.3),
list(type = "rect",
fillcolor = "grey", line = list(color = "white"),
x0 = 0.5, x1 = 1.0, xref = "x",
y0 = 0.0, y1 = 1.0, yref = "y",
opacity = 0.98)
)
plot_ly() %>%
layout(shapes = shapes) %>%
add_text(x = c(0.25, 0.75), y = 0.5, text = c("Easy Visible", "Barely visible"), textfont = list(color = '#000000'))
library(“plotly”)
形状%
布局(形状=形状)%>%
添加文本(x=c(0.25,0.75),y=0.5,text=c(“容易看到”,“几乎看不见”),textfont=list(颜色=”#000000'))
这将生成以下输出(使用不透明度参数,我们可以看到文本位于形状后面):
有没有关于如何在不透明形状前面添加文本的想法?将layer=“below”
选项添加到shapes
。它指定是在迹线下方还是上方绘制形状
shapes <- list(
list(type = "rect",
fillcolor = "red", line = list(color = "white"),
x0 = 0.0, x1 = 0.5, xref = "x",
y0 = 0.0, y1 = 1.0, yref = "y",
opacity = 0.3, layer="below"),
list(type = "rect",
fillcolor = "grey", line = list(color = "white"),
x0 = 0.5, x1 = 1.0, xref = "x",
y0 = 0.0, y1 = 1.0, yref = "y",
opacity = 0.98, layer="below")
)
plot_ly() %>%
layout(shapes = shapes) %>%
add_text(x = c(0.25, 0.75), y = 0.5,
text = c("Easy Visible", "Barely visible"),
textfont = list(color = '#000000'))
shapes%
布局(形状=形状)%>%
添加文本(x=c(0.25,0.75),y=0.5,
text=c(“容易看到”、“几乎看不见”),
text字体=列表(颜色='#000000'))
将layer=“below”
选项添加到形状
。它指定是在迹线下方还是上方绘制形状
shapes <- list(
list(type = "rect",
fillcolor = "red", line = list(color = "white"),
x0 = 0.0, x1 = 0.5, xref = "x",
y0 = 0.0, y1 = 1.0, yref = "y",
opacity = 0.3, layer="below"),
list(type = "rect",
fillcolor = "grey", line = list(color = "white"),
x0 = 0.5, x1 = 1.0, xref = "x",
y0 = 0.0, y1 = 1.0, yref = "y",
opacity = 0.98, layer="below")
)
plot_ly() %>%
layout(shapes = shapes) %>%
add_text(x = c(0.25, 0.75), y = 0.5,
text = c("Easy Visible", "Barely visible"),
textfont = list(color = '#000000'))
shapes%
布局(形状=形状)%>%
添加文本(x=c(0.25,0.75),y=0.5,
text=c(“容易看到”、“几乎看不见”),
text字体=列表(颜色='#000000'))
一种选择是使用注释而不是文本:
plot_ly() %>%
layout(shapes = shapes) %>%
add_annotations( x = c(0.25, 0.75),
y = c(0.5, .5),
xref = "x",
yref = "y",
text = c('Easy Visible', 'Also Easy Now'),
font = list(color = '#000000'), showarrow = F)
一种选择是使用注释而不是文本:
plot_ly() %>%
layout(shapes = shapes) %>%
add_annotations( x = c(0.25, 0.75),
y = c(0.5, .5),
xref = "x",
yref = "y",
text = c('Easy Visible', 'Also Easy Now'),
font = list(color = '#000000'), showarrow = F)
知道为什么网格线会使用这种方法返回吗?@astrofunkswag With
layer=“below”
彩色区域位于任何其他对象(网格线、文本等)的后面。你的解决方案很有趣。我喜欢!知道为什么网格线用这种方法返回吗?@astrofunkswag Withlayer=“below”
彩色区域放置在任何其他对象(网格线、文本等)的后面。你的解决方案很有趣。我喜欢!