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

Is it possible to handle the size or rotate of the x and y axis text? #9

Open
ManuelSpinola opened this issue Jun 20, 2022 · 1 comment
Assignees

Comments

@ManuelSpinola
Copy link

I would like to change the size or rotate the axis text, but I don't see any example to see how can I do it. I really appreciate the help with that.

@etiennebacher
Copy link

Hi @ManuelSpinola, you can control all the axis options with axis_x() and axis_y(). You can see the docs here to know what options can be applied to the axis labels.

If you're not familiar with it, the way to pass options can look a bit strange because it uses nested lists. The idea is that you must make a list for each "option level". For example, to increase the font size, the docs says that for the AxisOption, you go to label, then to style, then to fontSize (in shapeAttrs), so the corresponding code is:

axis_y(
    label = list( # level 1
      style = list( # level 2
        fontSize = 30 # level 3
      )
    )
  )

You can do something similar to rotate labels. Here's an example with bigger font size and rotated labels:

library(g2r)

df <- data.frame(
  x = letters,
  y = runif(26)
)

df$max <- 1

g2(df, asp(x, y), elementId = "x") %>% 
  fig_interval(asp(y = max), fill = "lightgrey") %>% 
  fig_interval(asp(, size = 8)) %>% 
  gauge_y_linear(min = 0, max = 1) %>%
  axis_x(
    label = list(rotate = 300, offset = 10)
  ) %>%
  axis_y(
    label = list(style = list(fontSize = 30))
  )

image

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

3 participants