-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemperaturePlot.R
36 lines (33 loc) · 1.49 KB
/
temperaturePlot.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
library(tidyverse)
# agregamos el archivo CSV mediante link
file_url <- "https://data.giss.nasa.gov/gistemp/tabledata_v4/SH.Ts+dSST.csv"
read_csv(file_url, skip = 1, na = "***") %>%
select(year = Year, t_diff = DJF) %>%
ggplot(aes(year, t_diff)) +
geom_line(aes(color = "1"), size = 0.5, show.legend = FALSE) +
geom_point(fill = "white", aes(color = "1"), color = "gray", shape = 21, show.legend = TRUE ) +
geom_smooth(se = FALSE, aes(color = "2"), size=0.5, span=0.15, show.legend = FALSE) +
scale_x_continuous(breaks=seq(1880, 2023, 20), expand=c(0,0))+
scale_y_continuous(limits=c(-0.5, 1.5), expand=c(0,0))+
scale_color_manual(name=NULL,
breaks=c(1,2),
values=c("gray", "black"),
labels=c("Media Anual", "Lowess smoothing (Regresión Local)"))+
labs(
x = "Año",
y = "Anomalía de temperatura (C°)",
title = "Índice de temperaturas del Hemisferio Sur\n1880 - 2022",
subtitle = "Fuente: NASA's Goddard Institute for Space Studies (GISS).\nCréditos: NASA/GISS"
)+
theme()+
theme(
axis.ticks = element_blank(),
plot.title.position = "plot",
plot.title = element_text(margin = margin(b=10), color = "red", face="bold"),
plot.subtitle = element_text(size=8, margin = margin(b=10)),
legend.position = c(0.15, 0.9),
legend.title = element_text(size=0),
legend.key.height = unit(8, "pt"),
legend.margin = margin(0,0,0,0)
)
ggsave("figures/temperaturePlot.png", width=6,height=4)