问题
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'))
回答1:
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.
来源:https://stackoverflow.com/questions/38260022/line-break-and-subscript-in-axis-title-using-plotly-in-r