-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsenegal.R
More file actions
90 lines (71 loc) · 1.96 KB
/
senegal.R
File metadata and controls
90 lines (71 loc) · 1.96 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
getwd()
setwd("C:/Users/tenin/Documents/BIMS/Climate model/senegal")
library(ggplot2)
library(lubridate)
library(dplyr)
library(tidyr)
install.packages("reshape2")
library(reshape2)
library(viridisLite)
library(hrbrthemes)
#read the dataframe
dfsen= read.csv(file="final_data_temp_seng.csv", header= TRUE, sep =";")
class(dfsen)
summarise(dfsen)
head(dfsen)
View(dfsen)
str(dfsen)
#convert date column class to date
dfsen$date= ymd(dfsen$date)
class(dfsen$date)
#plot data
p <- ggplot(dfsen, aes(x=date, y=Temp)) +
geom_line() +
xlab("Date") +
ylab("Temperature") +
ggtitle("temp 1901-2018 sen") +
theme_classic()
p
p + stat_smooth(
color = "#FC4E07", fill = "#FC4E07",
method = "loess")
# create a year column
dfsen$month <- month(dfsen$date)
dfsen$month= month.abb[dfsen$month]
match(dfsen$month,month.abb)
names(dfsen)
str(dfsen)
#month as factor
dfsen$month<- factor(dfsen$month, ordered= FALSE)
levels(dfsen$month)
dfsen$month= month.abb[dfsen$month]
df$month = factor(df$month)
str(dfsen)
# Create a group_by object using the month column
dfsen.month<- group_by(dfsen,month) # data_frame object month) # column name to group by
class(dfsen.month)
#plot
p <- ggplot(dfsen, aes(x=month, y=Temp)) +
geom_point() +
xlab("Date") +
ylab("Temperature") +
ggtitle(" monthly temp 1901-2018 sen ") +
theme_classic()
p
# create a boxplot
p= ggplot(dfsen, aes(x=month, y=Temp, fill=Temp)) +
geom_boxplot(notch = TRUE) +
scale_fill_viridis(discrete = FALSE, alpha=0.6) +
geom_jitter(color="blue", size=0.3, alpha=0.8) +
theme_ipsum() +
theme(
legend.position="none",
plot.title = element_text(size=11)
) +
ggtitle("monthly Temp 1901-2018 sen") +
xlab("")
p
#create a time serie
temp_sen <- ts(dfsen, start=c(1901,1), end=c(2018,1),frequency=12)
View(temp_sen)
plot.ts(temp_sen, ylab="Temperature", main=" Mean Temp seng", lty=c("dotted", "solid"))