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 plotly
...
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'))
In plotly, you can get linebreaks (and other text formatting) using html tags.
So piping
layout(xaxis=list(title='text with <br> linebreak'))
should work.
Hence, to get subscript labels use the <sub>
tag. For example
CO<sub>2</sub>
will give you
CO2.
Note you have to use <br>
or <br />
not <br/>
(without a space)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With