I have this graphic with a dataframe that starts in mar18 and ends in fev21. Despite that, R wrote fev18 and mar21.
How can I adapt this code of this video to my problem?
scale_x_date(breaks = "1 month", date_labels = "%b %y")
I have this graphic with a dataframe that starts in mar18 and ends in fev21. Despite that, R wrote fev18 and mar21.
How can I adapt this code of this video to my problem?
scale_x_date(breaks = "1 month", date_labels = "%b %y")
Did you try the limits
argument?
Edit:
I was wrong. For some reason, it's handled by expand
argument, not limits
.
set.seed(seed = 104653)
library(ggplot2)
df <- data.frame(
date = seq.Date(
from = as.Date(x = "2018-03-01"),
to = as.Date(x = "2021-02-01"),
by = "1 month"
),
price = rnorm(n = 36)
)
ggplot(data = df) +
geom_line(mapping = aes(
x = date,
y = price
)) +
scale_x_date(
date_breaks = "1 month",
date_labels = "%b %y",
expand = c(0, 0)
) +
theme(axis.text.x = element_text(angle = 90))
Hope this helps.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.