我有一个带有标签的plotly
分组条形图。我可以更改标签上的字体大小,但是plotly
不允许字体超过某个特定限制,该限制似乎由条的宽度/高度确定。当要绘制大量的组和/或值时,这将成为问题。在某些情况下,文本不会变得比例如8号字体大。有没有超出此限制的方法?
这里有一些示例代码:
library(dplyr)
library(plotly)
data.frame(Desc = c("A", "A", "B", "B", "C", "C"),
Group = c("Group1", "Group2", "Group1", "Group2", "Group1", "Group2"),
Value = c(5, 4, 6, 4, 5, 3)) %>%
plotly::plot_ly(data = .) %>%
plotly::add_trace(x = ~Value,
y = ~Desc,
color = ~Group,
type = 'bar',
text = ~Value,
textposition = "outside",
textfont = list(size = 10), # size is defined here
)
您可以使用layout
并设置uniformtext
来更改文字大小。我增加了x轴范围以使大数适合。
suppressPackageStartupMessages({
library(dplyr);
library(plotly)})
data.frame(Desc = c("A", "A", "B", "B", "C", "C"),
Group = c("Group1", "Group2", "Group1", "Group2", "Group1", "Group2"),
Value = c(5, 4, 6, 4, 5, 3)) %>%
plotly::plot_ly(data = .) %>%
plotly::add_trace(x = ~Value,
y = ~Desc,
color = ~Group,
type = 'bar',
text = ~Value,
textposition = "outside"
) %>% layout(xaxis=list(range=c(0, max(.$Value)+2)),
uniformtext=list(minsize=36, mode='show'))
由reprex package(v0.3.0)在2020-05-29创建