轴标题中的换行符和下标,在R中使用plotly [英] line break and subscript in axis title using plotly in R

查看:662
本文介绍了轴标题中的换行符和下标,在R中使用plotly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始将plotly用于R中的一些交互式散点图,并且在轴标签上遇到了困难.通常,我先用ggplot2设计图,然后使用ggplotly函数将其转换,但是出于某些原因,这有时会很慢.所以我想直接在plotly ...

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'))

推荐答案

在绘图中,您可以使用html标签获取换行符(和其他文本格式).

In plotly, you can get linebreaks (and other text formatting) using html tags.

所以管道

layout(xaxis=list(title='text with <br> linebreak'))

应该工作.

因此,要获取下标标签,请使用<sub>标记.例如

Hence, to get subscript labels use the <sub> tag. For example

CO<sub>2</sub>

会给你

CO 2 .

这篇关于轴标题中的换行符和下标,在R中使用plotly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆