ggplotly文字美观,导致geom_line无法显示 [英] ggplotly text aesthetic causing geom_line to not display

查看:189
本文介绍了ggplotly文字美观,导致geom_line无法显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用由文字美学定义的工具提示来渲染简单的geom_line.

I'm trying to render a simple geom_line with a tooltip defined by a text aesthetic.

q <- ggplot(data = graphDataFactor(), aes(x = Dates,
                                          y=Variable_Data, 
                                          colour = Variable_Name
                                          #,
                                        #text = paste('Date: ', as.Date(Dates),
                                        #'<br>Variable:', Variable_Name,
                                        #'<br>Var Unit:', Variable_Data
                                                  #)
                                                  )) + 
          geom_line(size = 1) + 
          labs(colour = "Variables") 
ggplotly(q
         #, tooltip = c("text")
         )

因此,这段带有美感文字的代码可以很好地工作并渲染线条.但是,当我尝试使用文字美学和工具提示时,geom_line不会出现在图中.将鼠标悬停在正确的位置上确实会显示正确的工具提示,并且颜色图例会正确显示.

So this code with the text aesthetic commented out works fine and renders the line. However, when I try to use the text aesthetic and tooltip, the geom_line does not appear in the plot. Hovering over the correct locations does show the right tooltip, and the colour legend displays properly.

另外,我有一个相同的调用,唯一的区别是我调用geom_point而不是geom_line,并且呈现得很好.

Also, I have an identical call where the only difference is that I call geom_point rather than geom_line and that renders perfectly fine.

这仅仅是ggplotly的错误,还是我的代码有问题?

Is this just a bug with ggplotly or is there something wrong with my code?

推荐答案

设置美感时添加group=1.

library(plotly)
set.seed(1234)
df <- data.frame(Dates = c("01/14/92", "02/27/92", "03/27/92", "04/28/92", "01/03/92"),
                 Variable_Data=runif(5), Variable_Name=c("A","A","A","B","B"))
df$Dates <- as.Date(df$Dates,"%m/%d/%y")

q <- ggplot(data = df, aes(x=Dates, y=Variable_Data, 
                           colour=Variable_Name, group=1,
     text = paste('Date: ', Dates,
                  '<br>Variable:', Variable_Name, 
                  '<br>Var Unit:', Variable_Data))) + 
     geom_line(size = 1) + labs(colour = "Variables") 

ggplotly(q, tooltip = "text")

这篇关于ggplotly文字美观,导致geom_line无法显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆