1

I am trying to change both the yaxis scale and the amount of decimal places. I am using ylim() (to change y scale) and scale_y_continuous(labels = scales::number_format(accuracy = 0.01)) (from scale package to change the decimal points) but they wont work together. I am using ggplot to plot my data.

jay.sf
  • 60,139
  • 8
  • 53
  • 110
  • 1
    It's much easier to help if you can share sample data and any code you've tried. That saves potential answerers from having to guess what your data looks like and what output you're expecting. – TarJae Jul 11 '22 at 05:03

1 Answers1

0

If you use limits in scale_y_continuous, it will work.

Also you may want to use label_number instead of number_format, because, number_format is superseded by label_number as per the documentation,

These functions are kept for backward compatibility; you should switch to label_number()/label_comma() for new code.

library(ggplot2)

ggplot(mtcars, aes(x = mpg, y = drat)) +
  geom_point() +
  scale_y_continuous(
    labels = scales::label_number(accuracy = 0.1), 
    limits = c(3, 4)
  )

enter image description here

(Using mtcars built-in data for demo)

shafee
  • 15,566
  • 3
  • 19
  • 47