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

How can I change the height and width of the elements (rectangles) on the heat map? #613

Open
SerhEL opened this issue Jan 15, 2024 · 3 comments

Comments

@SerhEL
Copy link

SerhEL commented Jan 15, 2024

I want to change the width and height of the heatmap elements to make them square. Here is my code:

library(echarts4r)
library(dplyr)

table <- "kn    ln  gr  cn
1   BA  BA  10
1   XB  XB  1
2   FL  XB  5
2   GS  BC  6
3   GG  BC  4
3   BS  BA  0"

df <- read.table(text = table, header = TRUE, sep = "\t")

df_grouped <- df |> 
  arrange(gr, ln) |> 
  mutate(ln = factor(ln, levels = unique(ln)))

df_grouped |> 
  e_charts(kn) |> 
  e_heatmap(ln, cn, name = "value") |> 
  e_x_axis(data = unique(df$kn)) |>
  e_y_axis(data = unique(df_grouped$ln),
           axisLabel = list(rotate = 0, interval = 0, fontSize = 10, color = 'black'),
           scale = TRUE,
           axisTick = list(alignWithLabel = TRUE)
  ) |>
  e_visual_map(cn) |> 
  e_toolbox(
    feature = list(
      dataZoom = list(
        xAxisIndex = 0,
        yAxisIndex = 0
      ),
      restore = list()
    )
  )

9Bhql

@JohnCoene
Copy link
Owner

I don't think you can directly affect that. Echarts.js is designed to be fully responsive.

If you want to do that you would have to force set the width and height of the plot in pixels.

@SerhEL
Copy link
Author

SerhEL commented Jan 15, 2024

I don't think you can directly affect that. Echarts.js is designed to be fully responsive.
If you want to do that you would have to force set the width and height of the plot in pixels.

Is it possible to calculate the optimal width on the X axis based on the number of labels?

@JohnCoene
Copy link
Owner

I don't think there is need for that normally width = height gives you a square with square grid.

You could do nrow * n_pixels maybe.

There maybe a fixed padding to add to height and/or width

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