JohnCoene / echarts4r

🐳 ECharts 5 for R
http://echarts4r.john-coene.com/
Other
585 stars 82 forks source link

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

Open SerhEL opened 5 months ago

SerhEL commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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