I wanted to remove the space between plotted line and y-axis as shown in Image 1. But when I have tried it, the x-axis text has been removed as shown in Image 2. I got some help from this question, but my case is different because I have Date
format column in my x-axis.
This is the code I used:
# Plot SSI3 for URB
URB_SSI3 <- URB %>% ggplot2::ggplot(aes(x = Date, y = SSI3, color = datasets)) +
geom_line(linewidth=0.3, linetype="solid") +
scale_color_manual(name=NULL, breaks = c("Observed", "ERA5.Land",
"GLDAS", "GLEAM"),
values = c("Orange", "Red", "purple", "black"),
labels = c("Observed", "ERA5-Land",
"GLDAS", "GLEAM"))+
#title and legend
scale_y_continuous(limits = c(-3, 3), breaks = -3:3) +
scale_x_continuous(breaks= seq(min(year(URB$Date)), max(year(URB$Date)), by = 2),
labels = seq(min(year(URB$Date)), max(year(URB$Date)), by = 2),
expand = c(0, 0)) +
ggtitle("URB-SSI3") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(colour = "black"),
axis.text.y = element_text(colour = "black"),
legend.background = element_blank(),
legend.position = c(0.5, 0.1),
legend.direction = "horizontal",
legend.key = element_rect(fill = "transparent"),
legend.key.width = unit(30, "pt")
# legend.justification = c(0.3, 0.5)
) +
guides(fill="none")
URB_SSI3
This is my data in google drive as .rds file.
Any thoughts please?