尖峰(下线)仅在ggplotly的第一个方面出现

时间:2018-03-23 02:08:57

标签: r plotly facet-wrap ggplotly

当我绘制facet_wrap()并将下划线放到x轴时,它们只会在第一个面上出现。我做错了什么或者这是一个错误吗? MWE:

library(plotly)
library(ggplot2)

gg<-ggplot(data = iris,
       aes(x = Sepal.Length,
           y = Sepal.Width,
           color = Species,
           group = Petal.Width,
           text=sprintf("Petal Width %s<br>Sepal Length: %s", Petal.Width, Sepal.Length)
       ))+
    geom_point()+
    facet_wrap(~Species)

ggplotly(gg,tooltip = "text")%>%
    layout(xaxis = list(showspikes = T))

方面1中的Dropline: Dropline in facet 1 方面2中没有下线: No dropline in facet 2

1 个答案:

答案 0 :(得分:0)

我认为你必须分享x或y轴。所以你可以试试:

gg<-ggplot(data = iris,
           aes(x = Sepal.Length,
               y = Sepal.Width,
               color = Species,
               group = Petal.Width,
               text=sprintf("Petal Width %s<br>Sepal Length: %s", Petal.Width, Sepal.Length)
           ))+
    geom_point()+
    facet_grid(Species~.)

ggplotly(gg,tooltip = "text")%>%
    layout(xaxis = list(showspikes = T))

gg<-ggplot(data = iris,
           aes(x = Sepal.Length,
               y = Sepal.Width,
               color = Species,
               group = Petal.Width,
               text=sprintf("Petal Width %s<br>Sepal Length: %s", Petal.Width, Sepal.Length)
           ))+
    geom_point()+
    facet_wrap(~Species)

ggplotly(gg,tooltip = "text")%>%
    layout(yaxis = list(showspikes = T))