I just started to use
plotly for some interactive scatter plots in R and having a hard time on axis labels. Normally I designed my plots with
ggplot2 and then using the
ggplotly function to convert them, but this is sometimes very slow for any reason. So I want to create my plots directly in
I am trying now to change the axis title and want to add line breaks and later I also want to add subscript labels. But I am already failing at the newline in the title. Is there any trick?
library(plotly) library(dplyr) plot_ly(mtcars, x = wt, y = mpg, text = rownames(mtcars), mode = "text") %>% layout(xaxis=list(title='text with\nlinebreak'))Answer1:
In plotly, you can get linebreaks (and other text formatting) using html tags.
layout(xaxis=list(title='text with <br> linebreak'))
Hence, to get subscript labels use the
<sub> tag. For example
will give you