简体   繁体   中英

ggplot - change y-axis label and scale manually

I have the following data (representing monthly average, minimum and maximum)

MONTH;MEDIAN;MIN;MAX
1;-736.12;-5272.96;5946.79
2;3340.83;284.72;15707.46
3;7144.85;2916.79;17659.6
4;9927.73;1660.99;19191.29
5;10986.7;3689.15;16474.34
6;1526.48;-8086.48;13430.86
7;-4415.36;-9244.11;27554.34
8;-3213.32;-8970.76;22089.98
9;-3435.17;-5293.95;12451.59
10;-5112.405;-7002.67;5237.85
11;-7820.8;-11170.12;1164
12;-6143.055;-10836.93;165.82

I would like to plot them (a line for the median values and a shadowing for min/max values). Therefore I have this code:

ggplot(amazon_ghm) +
geom_line(aes(MONTH, MEDIAN)) +
geom_ribbon(aes(MONTH, ymax = MAX, ymin = MIN), alpha = 0.5, fill = "skyblue")

I would like to change the label of the y axis from "MEDIAN" to "diff in runoff [m3/s]". Unfortunately each time I have an error linked with the usage of "in".

Moreover, the x axis is going from 0 until 12.5 with a 2.5 spacing. How can I change that, in order to have ax axis going from 0 until 12 with a 1 spacing?

ggplot(amazon_ghm) +
  geom_line(aes(MONTH, MEDIAN)) +
  geom_ribbon(aes(MONTH, ymax = MAX, ymin = MIN),
              alpha = 0.5,
              fill = "skyblue") + 
  ylab("diff in runoff [m3/s]") +
  scale_x_continuous("Month", breaks = 0:12)

and if you need it to extend all the way add

 + scale_x_continuous("Month", breaks = 0:12, expand = c(0,0))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM