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

Struggling with the order of heatmap axes #484

Closed
avenn98 opened this issue Nov 22, 2022 · 1 comment
Closed

Struggling with the order of heatmap axes #484

avenn98 opened this issue Nov 22, 2022 · 1 comment

Comments

@avenn98
Copy link

avenn98 commented Nov 22, 2022

Hello! I'm having difficulties with getting my heat map axes to order properly. I've tried arranging the data, and setting reorder = FALSE, but only one axis will be ordered properly: either the y-axis is in proper numeric order (1 - 24), or the x-axis is ordered properly (day of week, ordered factor), but never both.
image
image

Here is my code:

heatmap_df <- df %>% group_by(hour_of_day, day_of_week) %>% 
  summarise(jobs = n()) %>% 
  dplyr::ungroup() %>% 
  arrange(day_of_week) 
#arrange by day_of_week provides the correct x-axis, arrange by hour_of_day provides the correct y-axis

 
 heatmap_df |>
   e_charts(day_of_week, reorder = FALSE) |> 
   e_heatmap(hour_of_day, jobs) |> 
   e_visual_map(jobs) |> 
   e_title(text = "Heatmap of Successful API Requests by Day and Hour",
           subtext = "24 hour clock") %>% 
   e_tooltip(trigger = "item") 
@avenn98 avenn98 closed this as completed Nov 23, 2022
@kanahia
Copy link

kanahia commented Oct 24, 2023

Hi @avenn98, could you kindly share how you managed to reorder x axis based on factor levels?
I read in the manual one can reorder yaxis by echarts4r::e_y_axis(inverse = TRUE) but I am struggling to order x axis according to my factors levels.

[edit] I noticed it is not enough to set factor levels in the data. Data must be literally reordered to make it working:

data <- data.frame(
  x = c("B", "A", "C", "D", "E"),
  y = c("W", "X", "Y", "Z", "V"),
  value = c(5, 7, 3, 9, 2))

desired_order <- c("A", "B", "C", "D", "E")
data <- data %>% dplyr::arrange(match(x, desired_order))

but as you pointed, if you reorder one axis then the other one is getting messy...Any help is welcome!

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

No branches or pull requests

2 participants