【发布时间】:2020-01-07 14:15:06
【问题描述】:
我正在尝试使用ggplotly() 创建水平条形图。因为标签相当长,我插入了 HTML 换行符<br>。当使用ggplotly() 绘制数据时,标签确实被包装了,但标签左侧有很大的边距,基本上使包装无用。除了使用plot_ly(),还有什么办法可以解决这个问题吗?
library(ggplot2)
library(plotly)
df <- data.frame(a = "A very long label<br>that needs<br>to be wrapped", b = 10)
ggplotly({
ggplot(df, aes(a, b)) +
geom_col() +
coord_flip()
})
plot_ly(df, y = ~a, x = ~b, type = "bar", orientation = "h")
【问题讨论】:
-
This answer on How to maintain size of ggplot with long labels 详细说明了
ggplot2的不同选项,这些选项也可能适用于ggplotly。