I am trying to create a horizontal bar chart using ggplotly()
. Because the labels are rather long I inserted HTML line breaks <br>
. When plotting the data using ggplotly()
the label is indeed wrapped but there is big margin to the left of the label basically rendering the wrapping useless. Is there any way to fix this besides using plot_ly()
?
library(ggplot2)
library(plotly)
df <- data.frame(a = "A very long label<br>that needs<br>to be wrapped", b = 10)
ggplotly({
ggplot(df, aes(a, b)) +
geom_col() +
coord_flip()
})
plot_ly(df, y = ~a, x = ~b, type = "bar", orientation = "h")