Search code examples
rggplot2yaxis

Y-axis Scale Number in the Millions


Image created from the code-> I am trying to edit the Y-axis scale to represent the amount the rows of Id. The numbers needed to be shown on the scale are in the millions. I need to abbreviate the number in order for it to be seen on the visualization.

  ggplot(sleeptocalories1, aes(Id,TotalCalories) +
  geom_col(fill="steelblue") +
  theme(axis.text.x = element_text(angle = 90)) +
  theme(axis.text.y = element_text(angle = 45)) 

Solution

  • I like scales::label_number_si():

    ggplot(data.frame(x = 1:5, y = 10^(2:6)), aes(x, y)) +
      geom_col() +
      scale_y_continuous(labels = scales::label_number_si())
    

    enter image description here

    On your data, it might be:

    ggplot(sleeptocalories1, aes(Id,TotalCalories) +
      geom_col(fill="steelblue") +
      theme(axis.text.x = element_text(angle = 90)) +
      theme(axis.text.y = element_text(angle = 45)) + 
      scale_y_continuous(labels = scales::label_number_si())