-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathggplotPractise1.R
More file actions
132 lines (112 loc) · 3.95 KB
/
Copy pathggplotPractise1.R
File metadata and controls
132 lines (112 loc) · 3.95 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
library(ggplot2)
library(dplyr)
library(lubridate)
Audit <- read.csv(file = "R training/Audit.csv")
Audit
#has arguments
#1-data
#2-aesthetics(variable in x and y axis)
#
ggplot(data=Audit,aes(x=Gender,y=count))
geom_bar(stat = "identity",fill="cc163d")
labs(title="my first graph",x="Gender",y="count")
theme_bw()
#generating a table that counts gender
Gender_count <- Audit %>%
group_by(Gender) %>%
summarise(count=n())
#plotting a bar graph
Gender_plot <- ggplot(data=Gender_count,
aes(x=Gender,y=count))+
geom_bar(stat = "identity",fill="#cc163d")+
labs(title="Distribution of Gender",x="Gender",y="count") +
theme(plot.title =element_text(hjust = 0.5),
axis.text.x=element_text(angle=45,vjust=0.5) )
Gender_plot
#employment,education,marital,account
#count of marital
#generating a table that counts Marital
Marital_count <- Audit %>%
group_by(Marital) %>%
summarise(count=n())
Marital_count
#plotting a bar graph
Marital_plot <- ggplot(data=Marital_count,
aes(x=Marital,y=count))+
geom_bar(stat="identity",fill="green")+
labs(title = "Distribution of Marital",x="Marital",y="count")+
theme_classic()+
theme(plot.title = element_text(hjust=0.5),
axis.text.x = element_text(angle=45,vjust=0.5))
Marital_plot
#count of education
Education_count<-Audit %>%
group_by(Education) %>%
summarise(count=n())
#plot a bar graph
Education_plot <- ggplot(data=Education_count,
aes(x=Education,y=count))+
geom_bar(stat="identity",fill="blue")+
labs(title = "Distribution of Education",x="Education",y="count")+
theme_grey()+
theme(plot.title = element_text(hjust=0.5),
axis.text.x = element_text(angle=45,vjust=0.5))
Education_plot
#grouped bar graphs
Maritalgender <- Audit %>%
group_by(Marital,Gender) %>%
summarise(count=n())
Maritalgender_plot <- ggplot(data=Maritalgender,aes(x=Marital,y=count,fill=Gender))+
geom_bar(stat="identity",position = "dodge")+
labs(title = "Distribution by marital and gender",x="Marital",y="count")+
theme_classic()+
theme(plot.title = element_text(hjust=0.5))+
scale_fill_manual(values = c("brown","yellow"))
Maritalgender_plot
#Avarage income of Marital status
Maritalincome <- Audit %>%
group_by(Marital,Gender) %>%
summarise(Avearge=mean(Income))
Maritalincome
Maritalincome_plot <- ggplot(data=Maritalincome,aes(x=Marital,y=count,fill=Gender))+
geom_bar(stat="identity",position = "stack")+
labs(title = "Distributionof income by Marital and Gender",x="Marital",y="Average")+
theme_classic()+
theme(plot.title = element_text(hjust=0.5))+
scale_fill_manual(values = c("brown","yellow"))
Maritalincome_plot
###line graph
FlightDelay<-read.csv(file ="R training/FlightDelays1.csv",header=TRUE)
FlightDelay
#changing date colum to mdy
FlightDelay$date <- as.character(FlightDelay$date)
FlightDelay$date<-mdy(FlightDelay$date)
str(FlightDelay)
FlightDelay_count <- FlightDelay %>%
mutate(wday2=wday(date,label = TRUE)) %>%
group_by(wday2) %>%
summarise(count=n())
FlightDelay_plot <- ggplot(data=FlightDelay_count,aes(x=wday2,y=count,group=1,color=1))+
geom_line(color="red")+
labs(title="Distribution of flights by day",x="Day",y="count")+
theme_bw()+
theme(plot.title = element_text(hjust=0.5),
axis.text.x = element_text(angle=45,vjust=0.5))
FlightDelay_plot
#mutate wday from date column
FlightDelay10 <- FlightDelay %>%
mutate(wday=wday(date,label=TRUE))
FlightDelay10
#count of weather and date
FlightDelay_count <- FlightDelay10 %>%
mutate(weather=as.character(weather)) %>%
group_by(weather,wday) %>%
summarise(count=n())
FlightDelay_plot2 <- ggplot(data=FlightDelay_count,aes(x=wday,y=count,group=weather,color=weather))+
geom_line()+
labs(title="Distribution of weather by day",x="Day",y="count")+
theme_bw()+
theme(plot.title = element_text(hjust=0.5),
axis.text.x = element_text(angle=45,vjust=0.5))+
scale_colour_manual(values = c("brown","yellow"))
FlightDelay_plot2