-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemographics.R
167 lines (127 loc) · 5.81 KB
/
Demographics.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
install.packages("tidyverse", dependencies=TRUE)
install.packages("dplyr", dependencies=TRUE)
install.packages("ggalt", dependencies=TRUE)
install.packages("visdata", dependencies=TRUE)
install.packages("ggpubr", dependencies=TRUE)
install.packages("latticeExtra", dependencies=TRUE)
install.packages("sysfonts","showtext", dependencies=TRUE)
install.packages("PairedData", dependencies=TRUE)
install.packages("rstatix", dependencies=TRUE)
install.packages("PairViz", dependencies=TRUE)
install.packages("pyramid", dependencies=TRUE)
install.packages("ggplot2", dependencies=TRUE)
install.packages("hrbrthemes", dependencies=TRUE)
install.packages("wesanderson")
install.packages("cowplot")
library(wesanderson)
library(ggplot2)
library(dplyr)
library(ggalt)
library(tidyverse)
library(mosaic)
library("ggpubr")
library(latticeExtra)
library(sysfonts)
library("showtext")
library(PairedData)
library(rstatix)
library(XML)
library(reshape2)
library(pyramid)
library(cowplot)
blue <- "#0171CE"
red <- "#DE4433"
font_add_google("Lato")
showtext_auto(enable = TRUE, record = TRUE)
#-------------------Data Loading-----------
setwd("/Users/apoorvahungund/Desktop/UMass /DACSS 602")
demo<-read.csv2(file="SocialMedia_Cleaned.csv", sep = ",")
prepost<-read.csv2(file="prepost.csv", sep = ",")
#-------------------Age & Gender-----------
favstats(demo$AGE)
demo$AGE<-as.numeric(demo$AGE)
ggplot(demo, aes(x=factor(AGE)))+
geom_bar(width=0.7, fill="steelblue")+
theme_minimal()
ggplot(demo, aes(x=as.factor(AGE), fill=as.factor(AGE) )) +
geom_bar(width=0.5, fill = "steelblue") +
ggtitle("Participant Ages\nMean = 32.06; Standard Deviation = 8.12") +
xlab("Ages") + ylab("Frequency")+
scale_y_continuous(limits = c(0, 65), breaks = seq(0, 65, by = 2))
demo %>% count(GENDER_1)
demo %>% group_by(GENDER_1) %>% count(AGE)
ag_2<-demo %>%
group_by(GENDER_1) %>%
count(age_group)
demo["age_group"] = cut(demo$AGE, c(18, 20, 30, 40, 50, 60, 70, Inf), c("18-20", "21-30", "31-40", "41-50", "51-60", "61-70", "61-70"), include.lowest=TRUE)
ages <- c("18-20", "21-30", "31-40", "41-50", "51-60", "61-70")
males <- c(0,43,22,5,4,0)
females <- c(1,60,67,16,5,1)
data <- data.frame(males,females,ages)
pyramid(data)
age<-pyramids(Left=males, Llab="Males", Right=females, Rlab="Females", Center = ages,
Laxis=c(0,10,20,30,40,50,60,70), main="Participants Age - Mean = 32.06; Standard Deviation = 8.12")
#-------------------Internet to study--------
demo$IN_EDU<-as.factor(demo$IN_EDU)
edu<-demo %>%
count(IN_EDU)
ggplot(edu, aes(x=IN_EDU, y=n)) +
geom_bar(stat="identity", fill = "salmon4") +
ggtitle("Respondents that use internet to study") +
geom_text(aes(label=n, vjust=-1))+
xlab("") + ylab("Count")+
scale_y_continuous(limits = c(0, 230), breaks = seq(0, 230, by = 50))
#-------------------Income-----------
demo$INCOME<-as.factor(demo$INCOME)
demo %>% count(INCOME)
demo$INCOME <- factor(demo$INCOME, levels=c("Less than $10,000", "$10,000 - $19,999", "$20,000 - $29,999", "$30,000 - $39,999", "$40,000 - $49,999", "$50,000 - $59,999", "$60,000 - $69,999", "$70,000 - $79,999", "$80,000 - $89,999", "$90,000 - $99,999", "$100,000 - $149,999"))
ggplot(demo, aes(x=INCOME, fill=INCOME)) +
geom_bar(width=0.5, fill = "chartreuse4") +
#ggtitle("Annual Income ($)") +
xlab("Annual Income ($)") + ylab("Count")+ geom_text(stat='count', aes(label=after_stat(count)), vjust=-1)+
scale_y_continuous(limits = c(0, 60), breaks = seq(0, 60, by = 15))+
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))+
scale_x_discrete(limits = c("Less than $10,000", "$10,000 - $19,999", "$20,000 - $29,999", "$30,000 - $39,999", "$40,000 - $49,999", "$50,000 - $59,999", "$60,000 - $69,999", "$70,000 - $79,999", "$80,000 - $89,999", "$90,000 - $99,999", "$100,000 - $149,999"))
#-------------------Education-----------
demo %>% count(EDU_1)
demo$EDU_1 <- factor(demo$EDU_1, levels=c("High School (Not Completed)", "High School", "Associate's Degree", "Some College coursework", "Bachelor's Degree", "Master's or PhD"))
ggplot(demo, aes(x=EDU_1, fill=EDU_1)) +
geom_bar(width=0.5, fill = "darkslategray4") +
#ggtitle("Annual Income ($)") +
xlab("Education Levels") + ylab("Count")+ geom_text(stat='count', aes(label=after_stat(count)), vjust=-1)+
scale_y_continuous(limits = c(0, 150), breaks = seq(0, 150, by = 50))+
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
#-------------------Living Environment-----------
demo %>% count(LOC_1)
demo$LOC_1 <- factor(demo$LOC_1, levels=c("Urban", "Rural", "Other"))
ggplot(demo, aes(x=LOC_1, fill=LOC_1)) +
geom_bar(width=0.5, fill = "coral4") +
#ggtitle("Annual Income ($)") +
xlab("") + ylab("Count")+ geom_text(stat='count', aes(label=after_stat(count)), vjust=-1)+
scale_y_continuous(limits = c(0, 150), breaks = seq(0, 150, by = 50))
#-------------------Hours spent on internet-----------
favstats(demo$HOURS)
demo %>% count(HOURS)
demo$AGE<-as.numeric(demo$HOURS)
ggplot(demo, aes(x=factor(HOURS)))+
geom_bar(width=0.7, fill="steelblue")+
theme_minimal()
#-------------------PRE-POST-----------
favstats(demo$PRE)
favstats(demo$POST)
#prepost$PID<-as.factor(prepost$PID)
prepost$GROUP<-as.factor(prepost$GROUP)
prepost$VALUE<-as.numeric(prepost$VALUE)
prepost$CONDITION<-as.factor(prepost$CONDITION)
ggplot(prepost, aes(x=GROUPS, y=VALUE, fill=CONDITION)) +
geom_bar(position = "dodge", stat = "identity")+
ylim(0,6)
ggplot(prepost, aes(x=reorder(GROUPS,desc(GROUPS)), y=VALUE, fill=reorder(CONDITION, desc(CONDITION)))) +
geom_boxplot()+
geom_jitter(shape=16, position=position_jitter(0.2))+
scale_fill_manual(values = wes_palette("Darjeeling2"))+
xlab("Treatment Method")+
ylab("Pre and Post Willingness to Engage scores")+
guides(fill=guide_legend(title="Treatment Condition"))
res_aov<-aov(VALUE ~ CONDITION+GROUPS, data = prepost)
summary(res_aov)