hrbrmstr / taucharts

:bar_chart: An R htmlwidget interface to the TauCharts javascript library
http://rpubs.com/hrbrmstr/taucharts
Other
65 stars 10 forks source link

add vertical lines? #54

Open ignacio82 opened 9 years ago

ignacio82 commented 9 years ago

Is it possible to add vertical lines to a graph? like geom_vline in ggplot2

Right now I have this graph:

df1 <-
  structure(
    list(
      Timestamp = structure(
        c(
          1441814593, 1441818193,
          1441821398, 1441821449, 1441828375, 1441873127, 1441813676, 1441837436,
          1441843661, 1441885583, 1441966341, 1441985621, 1442048926, 1442321691,
          1442321740, 1442328339, 1442329081, 1442349761, 1442391375, 1442408140,
          1442417679, 1442496854, 1442506500
        ), tzone = "UTC", class = c("POSIXct",
                                    "POSIXt")
      ), Group = c(
        1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
        2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
      )
    ), .Names = c("Timestamp",
                  "Group"), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,-23L)
  ) %>% group_by(Group) %>% 
  arrange(Timestamp) %>% 
  mutate(count = row_number()) 

library(taucharts)
df1 %>% group_by(Group) %>% 
  arrange(Timestamp) %>% 
  mutate(count = row_number()) %>% 
  tauchart() %>% 
  tau_line("Timestamp", "count", "Group") %>% 
  tau_legend() %>% tau_tooltip() %>% 
  tau_guide_x(auto_scale=TRUE, label="Timestamp", tick_format="%b %d")

I would like to add two vertical lines:

vlines <- as.numeric(c(
  as.POSIXct("2015-09-11 00:00:00"),
  as.POSIXct("2015-09-15 00:00:00")
))   

Is that possible?

Thanks!

smach commented 8 years ago

+1 -- would love to add a horizontal line, too!

jeremiahpslewis commented 8 years ago

Hey! This functionality (horizontal and vertical lines) is currently provided with the annotations plugin. Unfortunately until https://github.com/hrbrmstr/taucharts/issues/64 is solved, there isn't an easy way to produce anything but dotted lines.

Hope this helps! /j

data <- data.frame(date = seq(Sys.Date(), Sys.Date() - 9, length.out = 10), revenue = rpois(10, 50))
tauchart(data) %>%
  tau_point("date", "revenue") %>%
  tau_guide_x(tick_format = "%d.%m") %>%
  tau_annotations(data.frame(dim = "date", val = data$date,
                             text = "Another day", position = "front",
                             color = '#4300FF'))
smach commented 8 years ago

Thanks very much. Your example making multiple lines works well for me. FYI this code in the tau_annotations help file does not appear to be adding one single line to each plot (at least for me):

data(cars_data)
tauchart(cars_data) %>%
  tau_point("milespergallon", c("class", "price"), color="class") %>%
  tau_annotations(data.frame(dim = "y", val = 50000,
       text = "Whoa there!", position = "front",
       color = '#4300FF'))
jeremiahpslewis commented 8 years ago

I know, sorry! It's fixed in this pull request: https://github.com/hrbrmstr/taucharts/pull/67 :)