1

I made this plot with the following code:

A %>% 
  drop_na(Roadgroup) %>% 
  drop_na(L.Share) %>% 
  filter(L.Share != "#DIV/0!")  %>% 

  ggplot(aes(x=LP.share, y=L.Share, colour=Ward)) +
  geom_point() 

https://i.stack.imgur.com/KtT9Q.png

How would I go about making the y axis labels match the format of the x axis? (with both 2 decimal places, and less densely cluttered)

Dave Gruenewald
  • 5,329
  • 1
  • 23
  • 35
  • Several answers worth reading here: https://stackoverflow.com/questions/15622001/how-to-display-only-integer-values-on-an-axis-using-ggplot2 – mrhellmann Jan 08 '20 at 16:46
  • It looks like your y-axis variable is a factor. Without a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that's just a guess – camille Jan 08 '20 at 16:49

1 Answers1

1

You can specify this with a function inside scale_y_continuous with the breaks argument:

A %>% 
  drop_na(Roadgroup) %>% 
  drop_na(L.Share) %>% 
  filter(L.Share != "#DIV/0!")  %>% 

  ggplot(aes(x=LP.share, y=L.Share, colour=Ward)) +
  geom_point() +
  scale_y_continuous(breaks = function(y) seq(floor(min(y, digits = 1)), 
                                              ceiling(max(y, digits = 1)), 
                                              by = 0.05))

You may need to modify my function(y) here to fit your needs (by changing digits, and by). However, if A$L.Share is a factor, you will need to convert this to a numeric in order for scale_y_continuous to work properly.

Dave Gruenewald
  • 5,329
  • 1
  • 23
  • 35
  • Thanks, this worked but as @Camille mentioned the problem was more that the numerical variable was imported in the wrong format as a character not numeric. – cells interlinked Jan 08 '20 at 21:46