I have the following data example:
structure(list(cycle_rounded = structure(c(1604188800, 1606780800,
1609459200, 1612137600, 1614556800, 1617235200, 1619827200, 1622505600,
1625097600, 1627776000, 1630454400, 1633046400, 1635724800, 1638316800,
1640995200, 1643673600, 1646092800, 1648771200, 1651363200, 1654041600
), tzone = "UTC", class = c("POSIXct", "POSIXt")), media = c(27.0163533756641,
27.3523628886565, 27.6874774847651, 27.9632663969036, 28.2324797447653,
28.5946591329209, 28.0774171223198, 27.0218334461407, 26.3074215031224,
25.762714516129, 25.9331010513628, 26.1019612833841, 27.4678015082705,
27.8551394156665, 27.61177313685, 28.5468447629364, 28.6978991786281,
29.0753629090163, NaN, NaN), desvio = c(0.349566729323312, 0.354049553514593,
0.316576405105695, 0.28004282459359, 0.339372318521672, 0.287591989484519,
0.312261182269958, 0.246786673478273, 0.358857114435788, 0.119453586990502,
0.256559466294029, 0.300030737021837, 0.348529074834953, 0.383358876272664,
0.465191392255828, 0.596852747140639, 0.324808751418437, 0.222745848411023,
NA, NA), year = c(2020, 2020, 2021, 2021, 2021, 2021, 2021, 2021,
2021, 2021, 2021, 2021, 2021, 2021, 2022, 2022, 2022, 2022, 2022,
2022)), row.names = c(NA, -20L), class = "data.frame")
And plot at this way:
ggplot(df, aes(x = cycle_rounded, y = media)) +
geom_ribbon(aes(y = media, ymin = media - desvio, ymax = media + desvio),
alpha = .2, fill = "red") +
geom_line(col = "grey10", linewidth = .5) +
geom_point(col = "grey10", size = 1) +
scale_x_datetime(date_labels = "%m", breaks = "1 month",
sec.axis = sec_axis(~., sec_axis(~ ., labels = year))) +
labs(x = "data", y = "temperatura") +
theme_classic() +
theme(axis.text.x = element_text(size = 12, angle = 45,
vjust = 1, hjust = 1, color = "black"),
axis.text.y = element_text(size = 12, color = "black"),
axis.title.x = element_text(size = 14, color = "black"),
axis.title.y = element_text(size = 14, color = "black"))
however the sec_axis won't works as I expected. I would like to shown years below the months as one value of year for all correspondent months.
Any helps are appreciated
Thanks, Wilson