Fix plotly ggplotly() Title Overlapping Plot When Title is Split on Two Lines(修复标题在两行上拆分时的 plotly ggplotly() 标题重叠图)
问题描述
在下面的示例中,标题的第二行与情节略有重叠.有没有办法通过增加标题和情节之间的间距来解决这个问题?
In the example below, the second line of the title overlaps slightly with the plot. Is there a way to fix this by increasing the spacing between the title and plot?
library(ggplot2)
library(plotly)
library(magrittr)
p1 <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) +
geom_point() +
ggtitle("A REALLY, REALLY, REALLY LONG TITLE THAT I WANT TO
SPLIT INTO TWO LINES")
p1
ggplotly() %>% config(collaborate=FALSE, cloud=FALSE, displaylogo=FALSE, modeBarButtonsToRemove=c("select2d", "sendDataToCloud", "pan2d", "resetScale2d", "hoverClosestCartesian", "hoverCompareCartesian", "lasso2d", "zoomIn2d", "zoomOut2d"))
推荐答案
Plotly 忽略尾随换行符,还需要 HTML 换行符 <br/>
而不是
换行(见最后的例子).
Plotly ignores trailing new line characters and also needs HTML breaks <br />
instead of
for new lines (see example at the end).
添加 <br/>
以手动打破标题并在布局中添加顶部 margin
(layout(gp, margin=list(t= 75))
).
Add <br />
to manually break your title and add a top margin
to your layout (layout(gp, margin=list(t = 75))
).
library(ggplot2)
library(plotly)
library(magrittr)
p1 <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) +
geom_point() +
ggtitle("A REALLY, REALLY, REALLY LONG TITLE THAT I WANT TO <br />
SPLIT INTO TWO LINES<br />
")
p1
gp <- ggplotly() %>% config(collaborate=FALSE, cloud=FALSE, displaylogo=FALSE, modeBarButtonsToRemove=c("select2d", "sendDataToCloud", "pan2d", "resetScale2d", "hoverClosestCartesian", "hoverCompareCartesian", "lasso2d", "zoomIn2d", "zoomOut2d"))
gp <- layout(gp, margin=list(t = 75))
gp
<小时>
ggplot
情节
这篇关于修复标题在两行上拆分时的 plotly ggplotly() 标题重叠图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:修复标题在两行上拆分时的 plotly ggplotly() 标题重叠图
基础教程推荐
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01