Alyssa Allsop
Alyssa Allsop

Reputation: 53

Any ideas how to get my axis labels to not overlap with the lines in highcharter in r?

I have spent forever trying to figure this out and cannot get the left side of a few of my labels to not intersect with the line. I have tried adjusting margins, padding, position, width, etc but nothing fixes it. I have attached a screenshot of the problem and also included the code below. I would appreciate any help with this!


## First create the data frame
 dname <- rep("University", 26)
nice_name <- c("Govt Grants Contracts as % Total Revenue", 
               "Net Income Positive", 
               "Private Gifts as % Total Revenue", 
               "Revenue per Student Change Over Time",
               "Total Govt Appropriations as % Total Revenue",
               "Tuition and Fees as % Total Revenue",
               "Academic Support as % Adjusted* Total Expenses",
               "Academic Support as % Adjusted* Total Expenses Change Over Time",
               "Discounts and Allowances Applied to Tuition and Fees per Student",
               "Discounts and Allowances Applied to Tuition and Fees per Student Change Over Time",
               "Instruction Expenses as % Adjusted* Total Expenses",
               "Instruction Expenses as % Adjusted* Total Expenses Change Over Time",
               "Scholarships Fellowships Expenses as % Adjusted* Total Expenses",
               "Scholarships Fellowships Expenses as % Adjusted* Total Expenses Change Over Time",
               "Student Service as % Adjusted* Total Expenses",
               "Student Service as % Adjusted* Total Expenses Change Over Time",
               "Value of Endowment as % Adjusted* Total Expenses",
               "Value of Endowment as % Adjusted* Total Expenses Change Over Time",
               "Restricted Assets to Total Assets Ratio",
               "Restricted Assets to Total Assets Ratio Change Over Time",
               "Total Current Assets as % Adjusted* Total Expenses",
               "Total Debt to Total Assets Ratio",
               "Total Debt to Total Assets Ratio Change Over Time",
               "Enrollment Change Over Time",
               "Retention Rate",
               "Retention Rate Change Over Time")
weighted_value <- c(0.000,  2.000,  0.000,  0.500,  0.000,  0.000, -0.477,  0.142, -0.062, -0.500,
                    -0.500, -0.214, -0.474, -0.337, -0.500,  0.196,  0.183, -0.014, -0.481,  0.122,
                    -0.750,  0.000, -0.020,  0.900,  0.500, -0.083)

score_per_inst_category <- c(rep(.417, 6), rep(-.213, 12), rep(-.369, 3), rep(-.01, 2), rep(.439, 3))
category <- c(rep("Revenue", 6), rep("Expenses", 12), rep("Assets", 3), rep("Debt", 2), rep("Student", 3))
subscore_val <- cbind(dname, category, nice_name, score_per_inst_category, weighted_value) 
subscore_val <- as.data.frame(subscore_val)
subscore_val$score_per_inst_category <- as.numeric(subscore_val$score_per_inst_category)
subscore_val$weighted_value <- as.numeric(subscore_val$weighted_value)


  # Asset
  categories_grouped <- subscore_val %>%
    select(category, nice_name) %>%
    distinct(category, nice_name) %>%
    group_by(name = category) %>% 
    summarise(categories = list(nice_name)) %>% 
    arrange(factor(name, levels = c("Revenue", "Expenses", "Assets", "Debt", "Student"))) %>%
    list_parse()
  
  


  ## Then create the chart
  subscore_val %>%
    #filter(category=={unique(.$category)[1]}) %>%
    hchart("column",
           hcaes(x=nice_name, y=weighted_value, group=dname), 
           animation=T, 
           allowPointSelect=T,
           connectorWidth=8,
           marker=list(radius=10)
    ) %>%
    hc_title(text = "School Comparison of the 5 Index Score Components",
             align = "center") %>% 
    hc_caption(text = "*Total expenses have been adjusted to not include hospital services expenses.") %>% 
    hc_yAxis(min=-2, max = 2,
             tickInterval=0.5,
             labels = list(style = list(fontSize = "1.5vh")),
             title = list(text = "Score",
                          style = list(fontSize = "2vh")),
             plotLines = list(
               list(
                 width = 2
               )
             )) %>%
    hc_xAxis(
      categories = categories_grouped,
      labels = list(style = list(fontSize = "1.5vh",
                                 textOverflow = "none"
      )),
      title = list(text = " ",
                   style = list(fontSize = "2vh"))
    ) %>%
    hc_add_dependency("plugins/grouped-categories.js") %>%
    hc_chart(inverted=T) %>%
    hc_size(width = 1000, height = 800) %>%
    hc_legend(
      align = "center",
      #verticalAlign = "top",
      layout = "vertical",
      x = 200,
      y = 0,
      margin = 3,
      title = list(text = 'Category<br/><span style="font-size: 9px; color: #666; font-weight: normal">(Click to hide)</span>')
    ) %>%
    hc_tooltip(sort = TRUE, table = TRUE)

Upvotes: 0

Views: 56

Answers (0)

Related Questions