【问题标题】:How to solve the arrow in geom_segment can‘t display under plotly如何解决geom_segment中的箭头无法在plotly下显示
【发布时间】:2018-04-22 08:57:39
【问题描述】:

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

【问题讨论】:

    标签: r ggplot2 plotly


    【解决方案1】:

    一个不优雅的解决方案:使用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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 2011-04-30
      • 2022-08-24
      • 2014-07-05
      • 2015-05-14
      相关资源
      最近更新 更多