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

textangle messes-up the row or column labels #101

Open
oolonek opened this issue Aug 9, 2023 · 1 comment
Open

textangle messes-up the row or column labels #101

oolonek opened this issue Aug 9, 2023 · 1 comment
Assignees
Labels

Comments

@oolonek
Copy link

oolonek commented Aug 9, 2023

First of all many thanks for this great package !

The example below illustrates this (textangle messes-up the row or column labels)

When no textangle is specified (tutorial code)

library(iheatmapr)
data(measles, package = "iheatmapr")

main_heatmap(measles, name = "Measles<br>Cases", x_categorical = FALSE,
             layout = list(font = list(size = 8))) %>%
  add_col_groups(ifelse(1930:2001 < 1961,"No","Yes"),
                  side = "bottom", name = "Vaccine<br>Introduced?",
                  title = "Vaccine?",
                  colors = c("lightgray","blue")) %>%
  add_col_labels(ticktext = seq(1930,2000,10),font = list(size = 8)) %>%
  add_row_labels(size = 0.3,font = list(size = 6)) %>% 
  add_col_summary(layout = list(title = "Average<br>across<br>states"),
                  yname = "summary")  %>%                 
  add_col_title("Measles Cases from 1930 to 2001", side= "top") %>%
  add_row_summary(groups = TRUE, 
                  type = "bar",
                  layout = list(title = "Average<br>per<br>year",
                                font = list(size = 8)))

We get a correctly aligned row labels.

image

When we specify a given textangle, here 20, the row labels are no longer evenly distributed.

main_heatmap(measles, name = "Measles<br>Cases", x_categorical = FALSE,
             layout = list(font = list(size = 8))) %>%
  add_col_groups(ifelse(1930:2001 < 1961,"No","Yes"),
                  side = "bottom", name = "Vaccine<br>Introduced?",
                  title = "Vaccine?",
                  colors = c("lightgray","blue")) %>%
  add_col_labels(ticktext = seq(1930,2000,10),font = list(size = 8)) %>%
  add_row_labels(size = 0.3,font = list(size = 6), textangle = 20) %>% 
  add_col_summary(layout = list(title = "Average<br>across<br>states"),
                  yname = "summary")  %>%                 
  add_col_title("Measles Cases from 1930 to 2001", side= "top") %>%
  add_row_summary(groups = TRUE, 
                  type = "bar",
                  layout = list(title = "Average<br>per<br>year",
                                font = list(size = 8)))

image

It looks like the spacing problem is more important for longer labels.

My understanding is that the rotation of the label is made using the center of the label.

➡️ Ideally, the end of the label (when the row_labels are on the left or col_labels on the bottom) or the beginning of the label (when the row_labels are on the right or col_labels on the top) should be used.

Would there be a way to fix this ?

@alanocallaghan
Copy link
Contributor

Seems we need an option to set h/vjust

@alanocallaghan alanocallaghan self-assigned this Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants