0

I have a large number of plots computed with ggplot, however when the y-axis has different number of digits, the left side of the plot are not aligned. They will not be inserted directly under / over each other, so a grid cannot be used. Nevertheless, I would like them to have the exact same size. How could this be achieved?

qplot(rnorm(10),1:10, colour = runif(10))
qplot(rnorm(10),1001:1010, colour = runif(10))

enter image description here enter image description here

Cœur
  • 37,241
  • 25
  • 195
  • 267
Acarbalacar
  • 714
  • 2
  • 7
  • 19

2 Answers2

0

You can manually adjust the y-axis labels to match lengths or just rotate everything 90 degrees. Although there might be better solution out there.

ggplot(data.frame(x=rnorm(10),y=1:10),aes(x,y, colour = x))+geom_point()+
   scale_y_continuous(breaks = seq(0,10,by=2),labels=c('0.000','2.000','4.000','6.000','8.000','10.000'))

enter image description here

ggplot(data.frame(x=rnorm(10),y=1001:1010),aes(x,y,colour = x) )+geom_point()+
   theme(axis.text.y = element_text(angle = 90))

enter image description here

Koundy
  • 5,265
  • 3
  • 24
  • 37
  • This rotation could be a solution, though I would prefer a solution that adjusts the distance between the plot and the label, such that they are aligned. +1 – Acarbalacar Aug 16 '16 at 06:46
-1

So would you like to have a fixed y-axis limits? you can use the coord_cartesian()

qplot(rnorm(10),1:10, colour = runif(10)) +
coord_cartesian(ylim = c(min(y_var), max(y_var)))

This shall fix the y-axis limits for all plots. Here y_var refers to the y variable being used for the y-axis

joel.wilson
  • 8,243
  • 5
  • 28
  • 48
  • This isn't what the OP wants. Your code adjusts the limits of the plot. OP's concern is the amount of white space occupied by the axis labels. – jdobres Aug 16 '16 at 15:43