When bar chart textposition = "inside", how do I shift the text within the bar?

Code:
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))

Output:
bar chart

When I try to use insidetextanchor with plot_ly(), it doesn’t register that I’m asking it to move the text to the middle. What am I doing wrong?


According to the Figure Reference for Plotly R (bar traces section):

insidetextanchor
Type: enumerated , one of ( "end" | "middle" | "start" )
Default: "end"

Determines if texts are kept at center or start/end points in textposition “inside” mode.

2 Likes