我用ggplot2画了一张图。由于定向图片,我在 geom_segment 中使用箭头选项。但是当我使用 ggplotly 在 plotly 下显示我的图片时,箭头消失了。如何显示箭头?
您可以运行以下代码进行调试。
positiox_positiony <- data.frame(x_position=1:2,y_position=3:4)
node_edge_xy <- data.frame(x=1,y=3,xend=2,yend=4)
p <- ggplot(positiox_positiony,aes(x=x_position,y=y_position))+
geom_point(color="red",size=10,alpha=0.8)+
geom_segment(data=node_edge_xy,aes(x = x,y = y,xend = xend,yend = yend),
arrow = arrow(length = unit(0.25,"cm"),ends="last",type="closed"))
p
ggplotly(p)
最佳答案
一个不雅的解决方案:使用 plotly
添加箭头注释。
g <- ggplotly(p) %>%
layout(annotations=list(
list(
x=positiox_positiony$x_position[2],
y=positiox_positiony$y_position[2],
showarrow=TRUE,
xref = "x",
yref = "y",
arrowhead = 2,
arrowsize = 1.5,
ax=-20,
ay=20
)
))
g
关于r - 如何解决geom_segment中的箭头在plotly下无法显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49964231/