在 ggplotly 中旋转刻度标签

问题描述 投票:0回答:1

我想在使用

ggplotly
时有一些旋转的刻度标签。不幸的是,转换为 ggplotly 后,标签旋转回正常状态。这是一些可重现的示例:

library(plotly)
library(ggplot2)
p <- ggplot(iris, aes(x = Species, y = Sepal.Length)) +
  geom_boxplot() +
  guides(x =  guide_axis(angle = 90))
p

ggplotly(p)

创建于 2024-04-03,使用 reprex v2.0.2

所以,我想知道使用 ggplotly 时如何旋转标签?

r ggplot2 ggplotly
1个回答
0
投票

在写问题时我找到了答案。我们可以使用

layout
中的
plotly
函数并指定
tickangle
xaxis
,如下所示:

library(ggplot2)
library(plotly)
ggplotly(p) %>%
  layout(xaxis = list(tickangle = -90))

创建于 2024-04-03,使用 reprex v2.0.2

© www.soinside.com 2019 - 2024. All rights reserved.