将ggplotly与镶嵌面_wrap一起使用时,仅显示第一个镶嵌面的数据

将ggplotly与镶嵌面_wrap一起使用时,仅显示第一个镶嵌面的数据,r,ggplot2,facet,facet-wrap,ggplotly,R,Ggplot2,Facet,Facet Wrap,Ggplotly,我正在使用ggplot()+geom\u boxplot()+facet\u wrap()为多个组绘制箱线图。我想在此对象上使用ggplotly()来使用悬停工具提示,以便快速查看与异常值关联的数据。(为什么我不只是在绘图上注释?我将向工具提示中添加自定义文本,其范围比我希望在绘图上的固定注释中显示的范围更广。) 当我使用ggplotly时,将显示面,但仅显示第一个面的数据。facet\u grid也是如此。(我更喜欢使用facet\u wrap,这样我就可以在不同的facet之间使用自由缩放。

我正在使用
ggplot()+geom\u boxplot()+facet\u wrap()
为多个组绘制箱线图。我想在此对象上使用
ggplotly()
来使用悬停工具提示,以便快速查看与异常值关联的数据。(为什么我不只是在绘图上注释?我将向工具提示中添加自定义文本,其范围比我希望在绘图上的固定注释中显示的范围更广。)

当我使用
ggplotly
时,将显示面,但仅显示第一个面的数据。
facet\u grid
也是如此。(我更喜欢使用
facet\u wrap
,这样我就可以在不同的facet之间使用自由缩放。)

有没有办法让
ggplotly
以这种方式处理facet?我没有看到任何东西。我见过其他例子,人们都有,但各方面都有

# make data: 
# B: normal distribution divided across 3 groups
# C: group Z is on a different scale
df <- data.frame(A = rep(LETTERS[seq( from = 24, to = 26 )], 26*5),
                 B = rnorm(26*15))
df <- df %>% mutate(C = ifelse(A == 'Z', B*7, 
                               ifelse(A == 'Y', B + 7, B)))

# plot using facet_wrap
pwrap <- ggplot(df, aes(y = C)) +
  geom_boxplot() +
  theme_classic() +
  facet_wrap(facets = 'A')
# ggplot object shows fine
pwrap

#使用刻面网格绘制

pgrid它确实来了,但是你看不到它,如果你
缩小
你填充并找到所有的绘图,你可以像下面那样修改你的代码使它工作,这里我已经将列的宽度更改为
平均值(df$C)
。 在旁注中,您可以在
facet\u wrap(facets='a',scales='free')
命令中使用
scales='free'
使其更好,但在这种情况下,您有三个垂直轴

pwrap <- ggplot(df, aes(y = C)) +
  geom_boxplot(width=mean(abs(df$C))) +
  theme_classic() +
  facet_wrap(facets = 'A')
# ggplot object shows fine
pwrap
ggplotly(pwrap)

pwrapPKumar的解决方案很接近(定义了x变量),但是x轴的行为仍然没有达到我的预期。解决方案是确保x变量是一个因子

# plot using facet_wrap
pwrap <- ggplot(df, aes(x = as.factor(A), y = C)) + # x is a factor (as.factor('X') also OK if trying to match PKumar's answer)
  geom_boxplot() +
  theme_classic() +
  facet_wrap(~A, scales='free') 

# ggplot object
pwrap

# now a functional 
ggplotly(pwrap)
#使用facet_wrap进行绘图

你试过这个答案吗?好像是相关的。谢谢你找到相关的问题。我尝试了一下这个问题和相关链接,但仍然发现我的数据存在漏洞。我还没有详细说明这些信息。这很有趣,因为它指出了我以前尝试失败的原因:每个组的x值都在变化。我不明白为什么对于ggplotly对象中的每个方面,x索引为1,即使在第二个版本中,定义了常量x值。我想我可以为每个方面定义一个x轴变换。我在[documentation]()中没有看到这方面的任何内容。实际上,将文档和PKumar的建议结合起来,得出了一个解决方案:x需要是一个因子。见解决方案。
pwrap <- ggplot(df, aes(y = C)) +
  geom_boxplot(width=mean(abs(df$C))) +
  theme_classic() +
  facet_wrap(facets = 'A')
# ggplot object shows fine
pwrap
ggplotly(pwrap)
# plot using facet_wrap
pwrap <- ggplot(df, aes(x = 'X', y = C)) +
  geom_boxplot() +
  theme_classic() +
  facet_wrap(~A, scales='free') 
# ggplot object shows fine
pwrap
ggplotly(pwrap)
# plot using facet_wrap
pwrap <- ggplot(df, aes(x = as.factor(A), y = C)) + # x is a factor (as.factor('X') also OK if trying to match PKumar's answer)
  geom_boxplot() +
  theme_classic() +
  facet_wrap(~A, scales='free') 

# ggplot object
pwrap

# now a functional 
ggplotly(pwrap)