r - 如何解决geom_segment中的箭头在plotly下无法显示

标签 r ggplot2 plotly

我用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

enter image description here

关于r - 如何解决geom_segment中的箭头在plotly下无法显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49964231/

相关文章:

r - 如何在 ggplot2 中调整 geom_tile 的比例?

r - 使用 ggplot_build 改变 ggplot2 图并在 plot_grid 中使用它

javascript - 从绘图中找不到 d3

r - Shiny 适合连续三个以上的值框

r - 错误: package or namespace load failed for ‘car’

r - 向日期添加正确的世纪,年份提供为 "Year without century", %y

r - 无法使用 ggplot2 绘制多线图

r - 具有连续彩虹颜色的热图

python - 如何以绘图方式格式化数字并避免转换为百万

python - 输入变量值后使用 Dash(来自 Plotly)在仪表板上输出值