-
Notifications
You must be signed in to change notification settings - Fork 0
/
100Voices - WordCloud Women.R
173 lines (136 loc) · 6.4 KB
/
100Voices - WordCloud Women.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
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
getwd()
Packages <- c("dplyr", "ggplot2", "readr",
"pdftools","stopwords","tidytext",
"stringi", "stringr", "scales",
"tidyr", "widyr", "ggraph", "igraph",
"quanteda", "topicmodels","lattice",
"robustbase", "cvTools", "NLP", "tm",
"readxl", "ggnet", "network", "sna",
"visNetwork", "threejs", "networkD3",
"ndtv", "htmltools","xlsx")
lapply(Packages, library, character.only = TRUE)
Voices <- file("data.txt")
Voices <- readLines(Voices)
Voices<- paste(Voices,collapse = " ")
Voices <- strsplit(Voices, split = " ") %>% unlist()
VoicesTable <- table(Voices) %>% as.data.frame()
Voices <- sapply(Voices,"removePunctuation",USE.NAMES = FALSE)
Voices <- sapply(Voices,"tolower",USE.NAMES = FALSE)
Voices <- sapply(Voices,"stripWhitespace",USE.NAMES = FALSE)
Voices <- sapply(Voices,"removeNumbers",USE.NAMES = FALSE)
Voices <- Voices[Voices!=""]
Voices <- Voices[Voices!=" "]
remove <- c(stopwords("eng"))
Voices <- sapply(Voices,"removeWords",words=remove, USE.NAMES = FALSE)
Voices <- Voices[Voices!=""]
Voices <- Voices[Voices!=" "]
VoicesTable <- as.data.frame(line = 1:1107, Voices)
# count
count_table <- VoicesTable %>%
dplyr::count(Voices, sort = TRUE)
#####################################################
##################### Wordcloud #####################
#####################################################
Packages2 <- c("SnowballC", "RColorBrewer", "ggthemes",
"extrafont","readr","wordcloud",
"wordcloud2", "ggwordcloud","gganimate")
lapply(Packages2, library, character.only = TRUE)
write.xlsx(count_table,"table.xlsx")
finaltable <- read_excel("table.xlsx")
sample <- finaltable %>% filter(n>=1)
##B3EE53
p<- ggplot(sample, aes(label = Voices, size = n)) +
geom_text_wordcloud(area_corr = TRUE, color= '#4D7142',
eccentricity = 1.3) +
scale_size_area(max_size = 10) +
theme_minimal() +
theme(text = element_text(family="Roboto"),
#plot.title = element_text(hjust = 0.5, color = "#4D7142", size = 14, face= "bold"),
#plot.subtitle = element_text(hjust = 0.5, color = "#7f6000", size = 12,face= "bold"),
#plot.caption = element_text(hjust = 0, color = "#7f6000", size = 8,face= "bold"),
plot.background = element_rect(fill = "white"))
# labs(title = "Wordcloud 100 Voices!",
# subtitle = "Frequency by word video",
# caption = "Data source: Videos collected")
for (shape in c("triangle-forward"
#"circle", "cardioid", "diamond",
#"square"#, "triangle-forward", "triangle-upright",
#"pentagon", "star"
)) {
set.seed(42)
print(ggplot(sample, aes(label = Voices, size = n)) +
geom_text_wordcloud(area_corr = TRUE, color= '#76A9EA',
eccentricity = 0.3) +
scale_size_area(max_size = 7) +
theme_minimal() +
theme(text = element_text(family="Segoe UI"))
+ ggtitle(shape))
}
#####
wordcloud(words = sample$Voices, freq = sample$n,
max.words = 400, random.order = FALSE, rot.per = 0.35,
colors = brewer.pal(8, "Dark2"))
wordcloud2(sample, size=1.6)
wordcloud2(sample, size=1.6, color='random-dark')
wordcloud2(sample, size=1.6, color=rep_len( c("green","blue"), nrow(sample) ) )
wordcloud2(sample, size=1.6, color='random-light', backgroundColor="black")
# circle # cardioid # diamond # triangle-forward
# triangle # pentagon # star
wordcloud2(sample, size = 0.7, shape = 'star')
wordcloud2(sample, size = 2.3, minRotation = -pi/6, maxRotation = -pi/6, rotateRatio = 1)
library(webshot)
webshot::install_phantomjs()
# Make the graph
my_graph <- wordcloud2(sample, size=1.5)
# save it in html
library("htmlwidgets")
saveWidget(my_graph,"worldcloud.html",selfcontained = F)
# and in png or pdf
webshot("tmp.html","fig_1.pdf", delay =5, vwidth = 480, vheight=480)
###############################
###############################
############ MAPS #############
###############################
###############################
library(leaflet)
library(readxl)
library(sp)
worldcities <- read_excel("C:/Users/isaac/OneDrive/Escritorio/Trabajos_R/100VoicesProject/worldcities1.xlsx")
View(worldcities)
worldcities$lng <- as.numeric(worldcities$lng)
worldcities$lat <- as.numeric(worldcities$lat)
awesome <- makeAwesomeIcon(
icon='glyphicon-globe',
library='glyphicon',
markerColor = "green",
iconColor = 'white'
)
map<- leaflet(options = leafletOptions(zoomControl = FALSE,
minZoom = 2,
dragging = TRUE)) %>%
addTiles() %>%
addProviderTiles(providers$Esri.WorldImagery, group = "World Imagery") %>%
addProviderTiles(providers$Stamen.TonerLite, group = "Toner Lite") %>%
addLayersControl(baseGroups = c("Toner Lite", "World Imagery")) %>%
#addProviderTiles("NASAGIBS.ViirsEarthAtNight2012") %>%
addAwesomeMarkers(data = worldcities, lng = ~lng,
lat = ~lat,
popup = ~paste("<h3>",country,"</h3>",
"<b>German Rank Global Risk:</b> ",rank,"<br>",
"<b>Rank Fatalities (1999-2018):</b> ",rank1,"<br>",
"<b>Rank Losses in million US$ (1999-2018):</b> ",rank3,"<br>",
"<b>Rank Losses per unit GDP in % (1999-2018):</b> ",rank4,"<br>",
"<b></b> ","<br>",
video,
sep = " "),
icon = awesome ) %>%
#clusterOptions = markerClusterOptions()
addMiniMap(toggleDisplay = TRUE,
tiles = providers$Stamen.TonerLite,
aimingRectOptions = list(color = "#ff7800", weight = 1, clickable = FALSE),
shadowRectOptions = list(color = "#000000", weight = 1, clickable = FALSE, opacity =
0, fillOpacity = 0),
strings = list(hideText = "Hide MiniMap", showText = "Show MiniMap"),
mapOptions = list())
saveNetwork(map,"C:/Users/isaac/OneDrive/Escritorio/Trabajos_R/100VoicesProject/Map100Voices.html", selfcontained = TRUE)