Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calendar question #34

Closed
jyjek opened this issue Oct 26, 2018 · 2 comments
Closed

calendar question #34

jyjek opened this issue Oct 26, 2018 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@jyjek
Copy link

jyjek commented Oct 26, 2018

Hi, thx for your work!

It isn't an error but I have a question.
How to make auto-separated years in a calendar?

I try something like that:

dates <- seq.Date(as.Date("2017-01-01"), as.Date("2018-12-31"), by = "day")
values <- rnorm(length(dates), 20, 6)
year <- data.frame(date = dates, values = values)
year %>% 
  e_charts(date) %>% 
  e_calendar(range = "2017",top="40") %>% 
  e_calendar(range = "2018",top="260") %>% 
  e_heatmap(values, coord.system = "calendar") %>% 
  e_visual_map(max = 30) %>% 
  e_title("Calendar", "Heatmap")%>%
  e_tooltip("item")

Is any solution like fill from ggplot?

year %>% 
  e_charts(date) %>% 
  e_calendar(range = fill(year)) %>% 
   e_heatmap(values, coord.system = "calendar") %>% 
  e_visual_map(max = 30) %>% 
  e_title("Calendar", "Heatmap")%>%
  e_tooltip("item")

Expected output : this
Thx for any advice!

@JohnCoene
Copy link
Owner

The API for the heatmap/calendar is a bit clunky, I'll work on improving that. The solution to what you want to achieve is over at #31.

@JohnCoene JohnCoene added the enhancement New feature or request label Nov 7, 2018
@JohnCoene JohnCoene self-assigned this Nov 7, 2018
@JohnCoene
Copy link
Owner

I think I came up with a reasonable solution. Use the functions as you would before, however, extract the year from the dates to plot then group the data by

dates <- seq.Date(as.Date("2017-01-01"), as.Date("2018-12-31"), by = "day")
values <- rnorm(length(dates), 20, 6)

year <- data.frame(date = dates, values = values)

year %>% 
  dplyr::mutate(year = format(date, "%Y")) %>% 
  dplyr::group_by(year) %>% 
  e_charts(date) %>% 
  e_calendar(range = "2017",top="40") %>% 
  e_calendar(range = "2018",top="260") %>% 
  e_heatmap(values, coord.system = "calendar") %>% 
  e_visual_map(max = 30) %>% 
  e_title("Calendar", "Heatmap")%>%
  e_tooltip("item") 

If you lay the calendars before running e_heatmap then the function will apply the data to its corresponding calendar, however if you add the calendars (e_calendar) afterwards then you will have to specify the index of calendar index (as in the previous example).

dates <- seq.Date(as.Date("2017-01-01"), as.Date("2018-12-31"), by = "day")
values <- rnorm(length(dates), 20, 6)

year <- data.frame(date = dates, values = values)

year %>% 
  dplyr::mutate(year = format(date, "%Y")) %>% 
  dplyr::group_by(year) %>% 
  e_charts(date) %>% 
  e_heatmap(values, coord.system = "calendar", 
    calendar = c(0 ,1)  # pass calendar indices
  ) %>% 
  e_calendar(range = "2017",top="40") %>% 
  e_calendar(range = "2018",top="260") %>% 
  e_visual_map(max = 30) %>% 
  e_title("Calendar", "Heatmap")%>%
  e_tooltip("item") 

Let me know if that works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants