dreamRs / apexcharter

:bar_chart: R Htmlwidget for ApexCharts.js
https://dreamrs.github.io/apexcharter
Other
138 stars 15 forks source link

yaxis title outside the graph boundaries #13

Closed Alik-V closed 4 years ago

Alik-V commented 4 years ago

Hi pvictor, Thanks a lot for your ongoing work on this library, it's super cool and useful!

I am having an issue trying to give name to y_axis where the text appears to be outside the plot boundary. Could you give me some help with this? Thanks! Reproducible example and picture of the result:

df <- data.frame(time = c(2020, 2025, 2030, 2035, 2040),
                 x = c(-10.1, -20.3, -30.4, -40.7, -50.8),
                 y = c(-3.4, -6.7, -10.1, -13.6, -16.9),
                 z = c(-6.8, -13.6, -20.3, -27.1, -33.9))
apexchart() %>%
  ax_chart(type = "bar") %>%
  ax_plotOptions(bar = bar_opts(
    horizontal = FALSE,
    dataLabels = list(
      position = "top"
    )
  )
  ) %>%
  ax_grid(show = FALSE
  ) %>%
  ax_series(list(
    name = "x",
    data = df$x),
    list(name = "y",
         data = df$y),
    list(name = "z",
         data = df$z)

  ) %>%
  ax_xaxis(categories = df$time) %>%
  ax_yaxis(show = TRUE,
           title = list(text = "Some text in millions units"
           )
  ) %>%
  ax_title(text = "Comparison of drug resource utilization") %>%
  ax_subtitle(text = "Inpatient, outpatient, emergency department") 

yaxis issue

Interestingly, the problem is only present when dealing with all negative values on y-axis.

pvictor commented 4 years ago

Hi Alik, Thanks! You're welcome :)

You're right something must be miscalculated with negative values, to fix you can set minimal width to y-axis labels like this :

ax_yaxis(
    show = TRUE, 
    labels = list(minWidth = 60), # <--- here
    title = list(text = "Some text in millions units")
  )

With your example (👍 for it) 60 seems to work fine.

Victor

Alik-V commented 4 years ago

Hi Victor,

Thanks a lot, worked like a charm! I will be following the development of the library, loving it so far!

Best wishes, Alik