我似乎无法使用add_text()使文本在散点图中的Plotly中旋转。
我只是试图获得与angle参数在ggplot中产生的结果相同的结果。在绘图中,如果需要的话,输出需要具有悬停文字。
示例-
library(dplyr)
library(plotly)
data <- data.frame(
x = 1:10,
y = runif(10,0,10),
lab = LETTERS[1:10]
)
# base output needed in ggplot
p <- data %>%
ggplot(aes(x,y)) +
geom_text(aes(label = lab, angle = 90))
# doesn't respect angle arg - not that I'm looking to use ggplotly
ggplotly(p)
# plotly version
plot_ly(data) %>%
add_text(
x = ~x,
y = ~y,
text = ~lab,
hovertext = ~paste0("Label is ", lab),
# things I've tried (generally one at a time..)
textfont = list(angle = 90, textangle = 90, orientation = 90, rotate = 90)
)
我确定我缺少明显的东西,但我无法对其进行追踪。帮助您!
看来解决方案是使用add_annotations()
而不是add_text()
。然后启用textangle
arg。