I draw a picture using ggplot2. I use arrow option in geom_segment because of directed picture. But when I display my pic under plotly using ggplotly, the Arrow disappear. How can I display the arrow ? You can run the following code to debug.
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)
An inelegant solution: add the arrow using plotly
annotations.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With