R 在plotly中复制带有刻面和箭头注释的ggplot2图表
我想在R 在plotly中复制带有刻面和箭头注释的ggplot2图表,r,ggplot2,plotly,ggplotly,R,Ggplot2,Plotly,Ggplotly,我想在plotly中复制ggplot2图表,为此,我尝试使用ggplotly功能。 图表如下(p\u箭头): 问题:第二个子地块没有注释 第二次审判: # add annotation in axis x2 and y2 pl2 <- pl1 %>% add_annotations( x = x_start, y = y_start, xref = "x2", yref = "y2", axref = "x2", ayref = "y2", text =
plotly
中复制ggplot2
图表,为此,我尝试使用ggplotly
功能。
图表如下(p\u箭头
):
问题:第二个子地块没有注释
第二次审判:
# add annotation in axis x2 and y2
pl2 <- pl1 %>% add_annotations(
x = x_start,
y = y_start,
xref = "x2",
yref = "y2",
axref = "x2",
ayref = "y2",
text = "",
showarrow = TRUE,
ax = x_end,
ay = y_end,
arrowcolor = "black"
)
pl2
#在轴x2和y2中添加注释
pl2%添加注释(
x=x_开始,
y=y_开始,
xref=“x2”,
yref=“y2”,
axref=“x2”,
ayref=“y2”,
text=“”,
showarrow=TRUE,
ax=x_端,
ay=y_结束,
arrowcolor=“黑色”
)
pl2
问题:第二个子批次中缺少该点
有没有办法复制
p\u-arrow
?如果在添加注释的两个调用中都将yref
设置到同一个轴上(即“y”
,而不是“y2”
),那么问题就解决了:
pl%添加注释(
x=x_结束,
y=y_结束,
xref=“x”,
yref=“y”,
axref=“x”,
ayref=“y”,
text=“”,
showarrow=TRUE,
箭头=3,
箭头大小=2,
ax=x_开始,
ay=y_开始
)
所以现在pl
看起来是这样的:
与原作相似(事实上比原作好一点):
在您的p_箭头
绘图中,两个箭头都显示在右上角-在远离点的面“0”中,在面1
中显示到点-这是有意的吗?@Tjebo是的,我想这样显示效果大小。在真实的情况下,它可能不会完全像那样,因为处理在[0,1]范围内,但对于离散的{0,1}情况,它就足够了。非常感谢,我没有注意到y-ref在面上是常数。顺便说一句,箭头看起来确实很漂亮。
# my trials in ggplotly
pl <- ggplotly(p)
#pl1 only annotates the fist subplot
pl1 <- pl %>% add_annotations(
x = x_start,
y = y_start,
xref = "x",
yref = "y",
axref = "x",
ayref = "y",
text = "",
showarrow = TRUE,
ax = x_end,
ay = y_end,
arrowcolor = "black"
)
pl1
# add annotation in axis x2 and y2
pl2 <- pl1 %>% add_annotations(
x = x_start,
y = y_start,
xref = "x2",
yref = "y2",
axref = "x2",
ayref = "y2",
text = "",
showarrow = TRUE,
ax = x_end,
ay = y_end,
arrowcolor = "black"
)
pl2