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

yaxis title outside the graph boundaries #13

Closed
Alik-V opened this issue Apr 30, 2020 · 2 comments
Closed

yaxis title outside the graph boundaries #13

Alik-V opened this issue Apr 30, 2020 · 2 comments

Comments

@Alik-V
Copy link

Alik-V commented Apr 30, 2020

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.

@Alik-V Alik-V changed the title yaxis outside the graph yaxis title outside the graph Apr 30, 2020
@Alik-V Alik-V changed the title yaxis title outside the graph yaxis title outside the graph boundaries Apr 30, 2020
@pvictor
Copy link
Member

pvictor commented Apr 30, 2020

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
Copy link
Author

Alik-V commented Apr 30, 2020

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

@Alik-V Alik-V closed this as completed Apr 30, 2020
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