jbkunst / highcharter

R wrapper for highcharts
http://jkunst.com/highcharter/
Other
717 stars 147 forks source link

date x axis not working/formating for "heatmap" #779

Open zackarno opened 1 year ago

zackarno commented 1 year ago

Hello, thanks for the great package !

It seems like creating and formatting a date x-axis on a "heatmap" either does not work as expected or it follows a different syntax than other charts?

library(lubridate)
library(tidyverse)
library(highcharter)

# create some fake data
dataset <- tibble(
  # will show example using date in both formates (date, dt below)
  date = seq(as.Date("2017-01-01"), as.Date("2017-02-01"), by = 1),
  dt = datetime_to_timestamp(date),
  numeric_fill = sample(1000:2000, size = 32),
  numeric_x = sample(c(1:8), size = 32,replace = T),
  categoric_y = sample(LETTERS[1:5],32, replace = T),

)

plot with categorical data on x axis - works as expected


plot_categorical_x <- hchart(dataset,
               "heatmap",
               hcaes(x = numeric_x, y = categoric_y,value=numeric_fill)
) 
plot_categorical_x

plot with date on x axis - sort of works.


plot_date_x <- hchart(dataset,
                "heatmap",
                hcaes(x = date, y = categoric_y,value=numeric_fill)
) 
plot_date_x

However, can't seem to format x-axis -- even though the tooltip can be formatted as expected


# here i try formatting x-axis and nothing happens - however, it does work in the tooltip
plot_date_x |> 
  hc_xAxis(dateTimeLabelFormats = list(month = "%m-%Y"), 
           type = "datetime") |> 
  hc_tooltip(pointFormat = "{point.x:%m-%Y}")

I try another a variation on dateTimeLabelFormats - still nothing changes


plot_date_x |> 
  hc_xAxis( dateTimeLabelFormats = list(day = '%d dayview', week = '%d weekview'), 
           type = "datetime") |> 
  hc_tooltip(pointFormat = "{point.x:%m-%Y}")

now we try using the dt variable created withdatetime_to_timestamp(date) and the values of the heatmap completely disappear. Adding hc_xAxis() and adjusting parameters (not shown) does nothing to bring back the data


plot_dt_x <- hchart(dataset,
                "heatmap",
                hcaes(x = dt, y = categoric_y,value=numeric_fill)
) 

plot_dt_x

Created on 2022-10-25 by the reprex package (v2.0.1)

stale[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Feel free to reopen it if you find it necessary.