line break and subscript in axis title using plotly in R

两盒软妹~` 提交于 2019-12-23 09:02:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!