如何在使用facet_grid和plotly的绘图中添加注释?

时间:2019-05-20 16:47:09

标签: r ggplot2 plotly

我有一个图表,但无法使注释生效。

我遵循了tutorial,并按如下方式设置了代码。

var gem : SKSpriteNode!

override func touchesBegan(_ touches: Set<UITouch>, with the event: UIEvent?) {

    gem = SKSpriteNode(fileNamed: "CoolGem")!
    gem.position = CGPoint(x: 0, y: 0)
    addChild(gem)
    gem.run(SKAction.move(to: CGPoint(x: Double.random(in: -100...100), y: Double.random(in: -100...100)), duration: 1))

}

这是我的数据。

library(tidyverse)
library(scales)
library(plotly)

gg <- bb %>% 
  ggplot(aes(week, value, color = type)) +
  geom_line() +
  scale_y_continuous(labels = function(x)(ifelse(x > 1000000, paste0("$", x / 1000000, "M"), 
                                                 ifelse(x < 1000000, paste0("$", x / 1000000, "M"),
                                                        ifelse(x > 1000, paste0("$", x / 1000, "K"), x))))) +
  facet_grid(type~., scales="free") +
  labs(x = NULL, y = NULL) +
  theme_light() +
  theme(legend.position = "none") 

mytext2 <- paste("Type = ", bb$type, "\n", "Week = ", bb$week, "\n", "Value = ", dollar(as.numeric(bb$value)), "\n", sep = "")
plotly_build(gg)   %>% 
  style(text=mytext2, hoverinfo = "text", traces = c(1, 2, 3)) %>% 
  layout(title = "A look at the Customer Journey Starting with Their First Week",
         font = list(size = 12),
         xaxis = list(title = "Weeks from Account Creation"),
         font = list(size = 9),
         yaxis = list(title = "Balance"),
         font = list(size = 9)
  ) 

您可以在此处的可视化图中看到每个标签都是# A tibble: 180 x 3 week type value <dbl> <chr> <dbl> 1 0 Median -32.0 2 1 Median -47.9 3 2 Median -0.01 4 3 Median 2.62 5 4 Median 94.8 6 5 Median 192. 7 6 Median 1352. 8 7 Median 2665. 9 8 Median 4085. 10 9 Median 4306. # … with 170 more rows 而不是正确的类型。

  

以下是可视化内容:https://rpubs.com/sebrpubs/example

0 个答案:

没有答案