0

In the image shown, I would like to compress the y-axis. The code I have is here:

plotoverall <- aggregAll %>%
               group_by(date) %>%
               summarise(Overall_kWh= sum(kWh, na.rm=TRUE)) %>%
               ggplot(aes(x = date, y = Overall_kWh, color="light blue" )) +
               geom_line(color="light blue", size=2) +
               theme(axis.text=element_text(size=12),
               axis.title=element_text(size=14))+
               #geom_point(color="blue") +  
               scale_y_continuous(name="Monthly million kWh",breaks=c(0,40000000,50000000,60000000),
                 labels = c("0","40","50","60"),
                 limits = c(0,60000000))
aosmith
  • 34,856
  • 9
  • 84
  • 118
  • Hi. Sorry, what do you mean by "compress the y-axis" ? – lbusett Feb 22 '17 at 21:21
  • Sorry, I mean that there is no y value between 0 and 40 and then only values between 40-60. So I want to be able to compress or break the Y axis. – Sam Fernandes Feb 22 '17 at 22:38
  • http://imgur.com/a/s05pY – Sam Fernandes Feb 22 '17 at 22:42
  • You just have to change the limits of the scale. this should do it: `scale_y_continuous(name="Monthly million kWh",breaks=c(40000000,50000000,60000000), labels = c("40","50","60"), limits = c(40000000,60000000))` – lbusett Feb 22 '17 at 23:10
  • Thanks, yes thats good, but now the "0" disappears on the y axis. I do also need to show the "0" level. – Sam Fernandes Feb 22 '17 at 23:19
  • mmm... why ? A line graph is legit even without the "0 level" (though it is considered to be bad practice for bar charts). However, ggplot doesnt allow broken axes (http://stackoverflow.com/questions/7194688/using-ggplot2-can-i-insert-a-break-in-the-axis). Don't know for other plotting packages, – lbusett Feb 22 '17 at 23:30
  • 1
    Doesn't seem like there's a point in showing 0 if its position doesn't correspond to 0. But you can put a zero label anywhere you want, e.g., `scale_y_continuous(name="Monthly million kWh",breaks=c(3:6 * 1e7), labels = c("0", "40","50","60"), limits = c(3, 6) * 1e7)`. – Gregor Thomas Feb 23 '17 at 17:38

0 Answers0