我试图使用plotly
长条形图绘制条形图作为x轴标签.但是,这些字符串被截断,plotly
如下所示:
通过plotly
轴的属性列表,我已经尝试过设置诸如tickangle
(现在我意识到这一点没有意义)和其他几个,但都没有用.
Jot*_*ota 21
您可以在layout
函数中调整图形布局中的边距.
可重复的例子,因为没有提供:
d <- data.frame(traitMean = apply(iris[-5], 2, mean))
# long labels
labs <- c("Long name for this", "Long name for that",
"Long names everywhere", "Petal Width")
Run Code Online (Sandbox Code Playgroud)
如果使用默认边距绘制此标签,标签将被截止:
# example where ticklabels are cutoff
plot_ly(y = d[["traitMean"]], x = labs, type = "bar") %>%
layout(xaxis = list(tickangle = 45))
Run Code Online (Sandbox Code Playgroud)
您可以从margin
参数中的默认值调整底部边距layout
. margin
获取一个命名列表,其中b
是"底部"边距的名称.160 px适用于此示例,但您可能需要找到适用于您的标签的值.
plot_ly(y = d[["traitMean"]], x = labs, type = "bar") %>%
layout(margin = list(b = 160), xaxis = list(tickangle = 45))
Run Code Online (Sandbox Code Playgroud)
当textposition="outside"
. 为了避免这种情况,除了设置边距以修复 y 轴标签截断之外,还要设置cliponaxis = FALSE
来修复值标签截断。
以下是值标签截断的示例,尽管添加了顶部和底部边距以删除 y 轴标签截断:
library(plotly)
plot_ly(
x = c("1. Group 1", "2. Txn","3. AOV","4. Account/Recv CV","5. Cost %","6. Lost %","7. Take Rate","8. Group 2"),
y = c(3.8,0,0,0,0,0,0,3.8),
name = "SF Zoo",
type = "waterfall",
measure = c("relative", "relative", "relative", "relative", "relative", "relative", "relative","total"),
text = c(3.8,0,0,0,0,0,0,3.8), textposition = 'outside'
) %>%
layout(margin = list(b = 20,t=20))
Run Code Online (Sandbox Code Playgroud)
当您添加时,cliponaxis = FALSE
切断被删除
plot_ly(
x = c("1. Group 1",
"2. Txn",
"3. AOV",
"4. Account/Recv CV",
"5. Cost %",
"6. Lost %",
"7. Take Rate",
"8. Group 2"),
y = c(3.8,0,0,0,0,0,0,3.8),
name = "SF Zoo",
type = "waterfall",
measure = c("relative", "relative", "relative", "relative", "relative", "relative", "relative","total"),
text = c(3.8,0,0,0,0,0,0,3.8), textposition = 'outside', cliponaxis = FALSE
) %>%
layout(margin = list(b = 20,t=20))
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
归档时间: |
|
查看次数: |
14154 次 |
最近记录: |