代码:
library(plotly)
library(dplyr)
xValues <- c("drug1","drug2","drug3","drug4","drug5")
yValues <- c(5,10,15,20,25)
bar <- plot_ly(x = yValues,
y = xValues,
type = 'bar',
orientation = 'h',
text = xValues,
textposition = "inside",
insidetextanchor = "middle",
insidetextfont = list(color = '#000000'),
showlegend = F) %>%
layout(
xaxis = list(title = "Studies"),
yaxis = list(zeroline = FALSE,showline = FALSE,showticklabels = FALSE))
bar
输出:bar chart
[当我尝试在plot_ly()中使用insidetextanchor时,并没有注册我要它将文本移到中间。我在做什么错?
根据Figure Reference for Plotly R(条形跟踪部分):
insidetextanchor
Type:枚举,("end"
|"middle"
| "start"
之一)默认: "end"
确定在textposition
“内部”模式下文本是保留在中心还是起点/终点。
当我运行此代码时,文本将按预期显示在中间。更新软件包和R