-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathR_inta_LC3_2019.R
179 lines (150 loc) · 5.99 KB
/
R_inta_LC3_2019.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
168
169
170
171
172
173
174
175
176
177
178
179
#chequeo si tengo instalados los paquetes necesarios
if(!require(pacman))install.packages("pacman")
#instalo un paquete que no está en CRAN
devtools::install_github('bbc/bbplot')
#Cargo paquetes necesarios para los gráficos
pacman::p_load('dplyr', 'tidyr', 'readxl',
'ggplot2', 'ggalt',
'forcats', 'R.utils', 'png',
'grid', 'ggpubr', 'scales',
'bbplot', 'likert')
#Empiezo a graficar
#Vamos a utilizar la información de la encuesta que generamos
#en la practica anterior, vamos a ver la generación de un
#gráfico paso a paso
#Paso 1
ggplot(data = encuesta)
#Paso 2
ggplot(data = encuesta, mapping = aes(x = Instituto))
#Paso 3
ggplot(data = encuesta, mapping = aes(x = Instituto)) +
geom_bar()
#Paso 4
ggplot(data = encuesta, mapping = aes(x = Instituto, fill=Instituto)) +
geom_bar()
#Paso 5
ggplot(data = encuesta, mapping = aes(x = Instituto, fill=Instituto)) +
geom_bar() +
geom_hline(yintercept = 0, size = 1, colour="#333333")+
labs(y="Cantidad de personas", x= "Institutos del CNIA")
#Paso 6
ggplot(data = encuesta, mapping = aes(x = Instituto, fill=Instituto)) +
geom_bar() +
geom_hline(yintercept = 0, size = 1, colour="#333333")+
labs(y="Cantidad de personas", x= "Institutos del CNIA")+
labs(title="Taller de R en INTA",
subtitle = "¿En qué Instituto trabajas?")
#Paso 7
ggplot(data = encuesta, mapping = aes(x = Instituto, fill=Instituto)) +
geom_bar() +
geom_hline(yintercept = 0, size = 1, colour="#333333")+
labs(y="Cantidad de personas", x= "Institutos del CNIA")+
labs(title="Taller de R en INTA",
subtitle = "¿En qué Instituto trabajas?")+
theme(axis.text.x = element_blank())
#Paso 8
ggplot(data = encuesta, mapping = aes(x = Instituto, fill=Instituto)) +
geom_bar() +
geom_hline(yintercept = 0, size = 1, colour="#333333")+
labs(y="Cantidad de personas", x= "Institutos del CNIA")+
labs(title="Taller de R en INTA",
subtitle = "¿En qué Instituto trabajas?")+
theme(axis.text.x = element_blank()) +
theme(legend.position="top", legend.text = element_text(size=10, face="bold"),
legend.title = element_blank())
#Vamos a graficar otras variables
#Vamos a utilizar el estilo BBC con la variable Asiste al taller
encuesta %>%
drop_na(Asiste) %>%
ggplot(mapping = aes(x = Asiste, fill=Asiste)) +
geom_bar() +
geom_hline(yintercept = 0, size = 1, colour="#333333")+
bbc_style() +
labs(title="Taller de R en INTA",
subtitle = "¿Venis al taller?")+
theme(axis.title = element_text(size = 14), legend.position = "none") +
labs(y="Cantidad de personas")
#Vamos a graficar que Plataforma se prefiere de dos formas:
#Estilo BBC con grafico de barras
encuesta %>%
drop_na(PlataformaComunidad) %>%
ggplot(mapping = aes(x = PlataformaComunidad, fill=PlataformaComunidad)) +
geom_bar() +
geom_hline(yintercept = 0, size = 1, colour="#333333")+
bbc_style() +
labs(title="Taller de R en INTA",
subtitle = "¿Qué plataforma preferís para seguir comunicados?")+
theme(axis.title = element_text(size = 14), axis.text.x = element_blank()) +
labs(y="Cantidad de personas")
#Estilo lollipop chart, para lo que tenemos que calcular la cantidad
#de respuestas (cosa que no es necesaria para el grafico de barras)
encuesta %>%
drop_na(PlataformaComunidad) %>%
group_by(PlataformaComunidad)%>%
summarise(cantidad=n()) %>%
ggplot(aes(x=PlataformaComunidad, y=cantidad)) +
geom_segment(aes(x=PlataformaComunidad, xend=PlataformaComunidad, y=0, yend=cantidad), color="grey") +
geom_point(color="orange", size=6) +
theme_light() +
theme(
panel.grid.major.x = element_blank(),
panel.border = element_blank(),
axis.ticks.x = element_blank()
) +
xlab("Plataforma") +
ylab("Cantidad")+
labs(title="Taller de R en INTA",
subtitle = "¿Qué plataforma preferís para seguir comunicados?")
#Cómo aprendió a usar R.
#Vamos a ponerlo en orden ascendente y descendente
#De mayor a menor
comoAprendio %>%
group_by(Herramienta)%>%
summarise(cantidad=n()) %>%
mutate(CategoriaOrdenada = fct_reorder(Herramienta, cantidad)) %>%
ggplot(aes(x=CategoriaOrdenada, y=cantidad)) +
geom_bar(stat="identity", fill="#f68060", alpha=.6, width=.4) +
coord_flip()+
xlab("") +
ylab("Cantidad")+
labs(title="Taller de R en INTA",
subtitle = "¿Cómo adquiriste tus conocimientos actuales en programación?")
# De menor a mayor
comoAprendio %>%
group_by(Herramienta)%>%
summarise(cantidad=n()) %>%
mutate(CategoriaOrdenada = fct_reorder(Herramienta, desc(cantidad))) %>%
ggplot(aes(x=CategoriaOrdenada, y=cantidad)) +
geom_bar(stat="identity", fill="#f68060", alpha=.6, width=.4) +
coord_flip() +
xlab("") +
ylab("Cantidad")+
labs(title="Taller de R en INTA",
subtitle = "¿Cómo adquiriste tus conocimientos actuales en programación?")
#Vamos a realizar un gráfico con Herramientas_Pivot
#puedo utilizar la tabla creada
Herramientas_Pivot %>%
group_by(Herramienta, Uso) %>%
summarise(cantidad=n()) %>%
drop_na() %>%
ggplot(aes(fill=Uso, y=cantidad, x=Herramienta)) +
geom_bar( stat="identity") +
bbc_style()+
geom_hline(yintercept = 0, size = 1, colour = "#333333") +
labs(title = "Conocimiento de Herramientas") +
theme(axis.text = element_text(size = 14)) +
labs(y = "Cantidad de participantes")
#o puedo generar el conjunto de datos y pasarlo a ggplot2 con el pipe
encuesta %>%
select(8:17) %>%
gather("Herramienta", "Uso") %>%
group_by(Herramienta, Uso) %>%
summarise(cantidad=n()) %>%
drop_na() %>%
ggplot(aes(fill=Uso, y=cantidad, x=Herramienta)) +
geom_bar( stat="identity") +
bbc_style()+
geom_hline(yintercept = 0, size = 1, colour = "#333333") +
labs(title = "Conocimiento de Herramientas") +
theme(axis.text = element_text(size = 14)) +
labs(y = "Cantidad de participantes")