在 R 中使用绘图的轴标题中的换行符和下标
line break and subscript in axis title using plotly in R
我刚开始使用 plotly
在 R 中绘制一些交互式散点图,但在轴标签上遇到了困难。通常我用 ggplot2
设计我的图,然后使用 ggplotly
函数转换它们,但有时由于某种原因这很慢。所以我想直接在 plotly
...
中创建我的地块
我现在正在尝试更改轴标题并想添加换行符,稍后我还想添加下标标签。但是我已经在标题的换行符处失败了。有什么技巧吗?
library(plotly)
library(dplyr)
plot_ly(mtcars, x = wt, y = mpg, text = rownames(mtcars), mode = "text") %>%
layout(xaxis=list(title='text with\nlinebreak'))
在 plotly 中,您可以使用 html 标签获取换行符(和其他文本格式)。
所以管道
layout(xaxis=list(title='text with <br> linebreak'))
应该可以。
因此,要获取下标标签,请使用 <sub>
标签。例如
CO<sub>2</sub>
会给你
CO2.
请注意,您必须使用 <br>
或 <br />
而不是 <br/>
(没有 space)
我刚开始使用 plotly
在 R 中绘制一些交互式散点图,但在轴标签上遇到了困难。通常我用 ggplot2
设计我的图,然后使用 ggplotly
函数转换它们,但有时由于某种原因这很慢。所以我想直接在 plotly
...
我现在正在尝试更改轴标题并想添加换行符,稍后我还想添加下标标签。但是我已经在标题的换行符处失败了。有什么技巧吗?
library(plotly)
library(dplyr)
plot_ly(mtcars, x = wt, y = mpg, text = rownames(mtcars), mode = "text") %>%
layout(xaxis=list(title='text with\nlinebreak'))
在 plotly 中,您可以使用 html 标签获取换行符(和其他文本格式)。
所以管道
layout(xaxis=list(title='text with <br> linebreak'))
应该可以。
因此,要获取下标标签,请使用 <sub>
标签。例如
CO<sub>2</sub>
会给你
CO2.
请注意,您必须使用 <br>
或 <br />
而不是 <br/>
(没有 space)