✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

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


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) %>%
xaxis = list(title = “Studies”),
yaxis = list(zeroline = FALSE,showline = FALSE,showticklabels = FALSE))

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

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

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

1 Like