r - Removing a white buffer within the graph -
i can't seem remove buffer on bottom (below green-low section) , top (above purple-extreme section) of data within graph.
i've tried extending rectangle down 0 , past 12, ggplot still adds white buffer. below code i'm using. feel free comment on other aspects of code if see better option 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 , adjust size of point shapes geom_line() + geom_point(size = 4) + ### set axis labels labs(x = "month", y = "uv index") + ### change order of legend alphabetical, , make shapes , lines 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 x axis 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 breaks on y-axis scale_y_continuous(breaks = 1:12) + ### add in color recatangles showing 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 identifies 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 , white themed plot. theme_bw() + ### adjust axis , 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 plot background eliminating lines cross entire graph showing units of 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())
thanks both @axeman , @zx8754 help. using expand = c(0,0)solved issue.

Comments
Post a Comment