I can't seem to remove the buffer on the bottom (below the green-low section) and top (above the purple-extreme section) of the data within the graph.
I've tried extending the rectangle down to 0 and past 12, but ggplot still adds the white buffer. Below is the code I'm using. Feel free to comment on other aspects of the code if you see a better option than what I used.
UV.plot.mean <- ggplot(data = UV.month.mean, aes(x = month, y = cloudy.sky.UVI, group = station.name, shape = station.name, color = station.name)) +
### Add in lines and adjust the size of the point shapes
geom_line() +
geom_point(size = 4) +
### Set the axis labels
labs(x = "Month", y = "UV index") +
### Change the order of the legend to alphabetical, and make the shapes and lines a color blind friendly palette.
scale_color_manual(values = CB.Cat, name = " ", labels = c("Albuquerque", "Atlanta", "Boise", "Buffalo", "Charleston", "Cheyenne", "Denver", "Memphis", "Phoenix")) +
scale_shape_manual(values = shapes, name = " ", labels = c("Albuquerque", "Atlanta", "Boise", "Buffalo", "Charleston", "Cheyenne", "Denver", "Memphis", "Phoenix")) +
### Adjust the x axis so it's chronologically in order instead of alphabetically
scale_x_discrete(limits = c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")) +
### Set the breaks on the y-axis
scale_y_continuous(breaks = 1:12) +
### Add in color recatangles showing the classification levels of UV radiation
annotate("rect", xmin = 0, xmax = 13, ymin = 11, ymax = 12, alpha = .1, fill = "purple") +
annotate("rect", xmin = 0, xmax = 13, ymin = 8, ymax = 11, alpha = .1, fill = "red") +
annotate("rect", xmin = 0, xmax = 13, ymin = 6, ymax = 8, alpha = .1, fill = "orange") +
annotate("rect", xmin = 0, xmax = 13, ymin = 3, ymax = 6, alpha = .1, fill = "yellow") +
annotate("rect", xmin = 0, xmax = 13, ymin = 1, ymax = 3, alpha = .1, fill = "green") +
### Add in text that identifies the levels of UV radiation
annotate("text", x = .5, y = 11.5, label = "Extreme") +
annotate("text", x = .5, y = 8.5, label = "Very High") +
annotate("text", x = .5, y = 6.5, label = "High") +
annotate("text", x = .5, y = 3.5, label = "Moderate") +
annotate("text", x = .5, y = 1.5, label = "Low") +
### Use black and white themed plot.
theme_bw() +
### Adjust the axis and legend
theme(axis.title.x = element_text(face = "bold", size = 16),
axis.title.y = element_text(face = "bold", size = 16),
legend.title = element_text(size = 24),
legend.position = c(1.01, 1.0),
legend.justification = c(1, 1),
legend.text = element_text(size = 24),
legend.background = element_blank(),
legend.key = element_blank()) +
### Adjust the plot background by eliminating the lines that cross the entire graph showing the units of the y axis.
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank())