LINKGUERRAS = "https://en.wikipedia.org/wiki/List_of_wars_by_death_toll"
library(htmltab)
ancient = htmltab(doc = LINKGUERRAS,
which ='//*[@id="mw-content-text"]/div/table[4]')
medieval = htmltab(doc = LINKGUERRAS,
which ='//*[@id="mw-content-text"]/div/table[6]')
## Warning: Columns [Notes] seem to have no data and are removed. Use
## rm_nodata_cols = F to suppress this behavior
modern = htmltab(doc = LINKGUERRAS,
which ='//*[@id="mw-content-text"]/div/table[7]')
## Warning: Columns [Notes] seem to have no data and are removed. Use
## rm_nodata_cols = F to suppress this behavior
names(ancient)
## [1] "War" "Deathrange" "Date" "Combatants" "Location"
## [6] "Notes"
names(medieval)
## [1] "War" "Deathrange" "Date" "Combatants" "Location"
names(modern)
## [1] "War" "Deathrange" "Date" "Combatants" "Location"
guerras1=ancient[,c("War","Location")]
guerras2=medieval[,c("War","Location")]
guerras3=modern[,c("War","Location")]
guerras=rbind(guerras1, guerras2, guerras3)
str(guerras)
## 'data.frame': 166 obs. of 2 variables:
## $ War : chr "Conquests of Cyrus the Great" "Greco–Persian Wars" "Samnite Wars" "Wars of Alexander the Great" ...
## $ Location: chr "Middle East" "Greece" "Italy" "Middle East / North Africa / Central Asia / India" ...
library(questionr)
library(magrittr)
NomDf=freq(guerras$Location,
total = F,exclude = c(NA))
guerrasTable=data.frame(variable=row.names(NomDf),
NomDf,row.names = NULL)
names(guerrasTable)=c("Paises","Conteo", "Porcentaje")
guerrasTable
## Paises Conteo Porcentaje
## 1 Afghanistan 3 1.8
## 2 Algeria 3 1.8
## 3 Americas 1 0.6
## 4 Angola 2 1.2
## 5 Balkan Peninsula 1 0.6
## 6 Bangladesh 1 0.6
## 7 Bosnia 1 0.6
## 8 British Isles 1 0.6
## 9 Burundi 1 0.6
## 10 Caucasus region 1 0.6
## 11 Central Africa 2 1.2
## 12 China 10 6.0
## 13 China, Korea 1 0.6
## 14 China, Vietnam 1 0.6
## 15 Colombia 3 1.8
## 16 Congo 4 2.4
## 17 Crimean Peninsula 1 0.6
## 18 Cuba 2 1.2
## 19 East Asia 1 0.6
## 20 Eastern Europe 3 1.8
## 21 Eastern Europe / Middle East / North Africa 1 0.6
## 22 El Salvador 1 0.6
## 23 England 2 1.2
## 24 England / Wales 1 0.6
## 25 Ethiopia 2 1.2
## 26 Eurasia 2 1.2
## 27 Europe 4 2.4
## 28 Europe / Americas 2 1.2
## 29 Europe / Middle East ("Holy Land") 1 0.6
## 30 Finland 1 0.6
## 31 France 3 1.8
## 32 Germany 1 0.6
## 33 Gran Chaco 1 0.6
## 34 Greece 3 1.8
## 35 Haiti 1 0.6
## 36 Iberian Peninsula 1 0.6
## 37 India 4 2.4
## 38 India-Bangladesh 1 0.6
## 39 Indonesia 1 0.6
## 40 Iraq 5 3.0
## 41 Italy 1 0.6
## 42 Korea 3 1.8
## 43 Laos 1 0.6
## 44 Lebanon 1 0.6
## 45 Libya 1 0.6
## 46 Madagascar 1 0.6
## 47 Manchuria 1 0.6
## 48 Mexico 4 2.4
## 49 Middle East 7 4.2
## 50 Middle East / North Africa 1 0.6
## 51 Middle East / North Africa / Central Asia / India 1 0.6
## 52 Middle East / North Africa / Southern Europe 1 0.6
## 53 Middle East/North Africa 1 0.6
## 54 Mozambique 1 0.6
## 55 Myanmar 1 0.6
## 56 Nigeria 2 1.2
## 57 North Africa 1 0.6
## 58 North America 1 0.6
## 59 North India / Pakistan 1 0.6
## 60 Northeast India 2 1.2
## 61 Northern China 1 0.6
## 62 Northern Europe 1 0.6
## 63 Pakistan 1 0.6
## 64 Patagonia 1 0.6
## 65 Peru 2 1.2
## 66 Philippines 3 1.8
## 67 Russia 2 1.2
## 68 Rwanda 1 0.6
## 69 Scotland / England 1 0.6
## 70 Sierra Leone 1 0.6
## 71 Somalia 1 0.6
## 72 South Africa 1 0.6
## 73 South America 1 0.6
## 74 Southeast Asia 3 1.8
## 75 Southeast Europe 1 0.6
## 76 Southern Africa 1 0.6
## 77 Southern Europe 1 0.6
## 78 Southern Europe / North Africa 2 1.2
## 79 Spain 2 1.2
## 80 Sri Lanka 1 0.6
## 81 Sudan 3 1.8
## 82 Syria 1 0.6
## 83 Tunisia 1 0.6
## 84 Uganda 1 0.6
## 85 USA 1 0.6
## 86 Venezuela 1 0.6
## 87 Vietnam 1 0.6
## 88 Western Europe 4 2.4
## 89 Western Europe / North Africa 2 1.2
## 90 Worldwide 7 4.2
## 91 Yemen 2 1.2
#Paises que tengan tres a más guerras
guerrasTable[guerrasTable$Conteo>=3,]
## Paises Conteo Porcentaje
## 1 Afghanistan 3 1.8
## 2 Algeria 3 1.8
## 12 China 10 6.0
## 15 Colombia 3 1.8
## 16 Congo 4 2.4
## 20 Eastern Europe 3 1.8
## 27 Europe 4 2.4
## 31 France 3 1.8
## 34 Greece 3 1.8
## 37 India 4 2.4
## 40 Iraq 5 3.0
## 42 Korea 3 1.8
## 48 Mexico 4 2.4
## 49 Middle East 7 4.2
## 66 Philippines 3 1.8
## 74 Southeast Asia 3 1.8
## 81 Sudan 3 1.8
## 88 Western Europe 4 2.4
## 90 Worldwide 7 4.2
library(ggplot2)
base = ggplot(data=guerrasTable[guerrasTable$Conteo>=3,],
aes(x=reorder(Paises,Conteo), #REORDENAR
y=Conteo))
bar1 = base + geom_bar(stat='identity')
bar1 = bar1 + labs(x="Pais/zona", y="Cantidad",
title="Ubicación de las Guerras en la historia",
subtitle = "Solo con más de 25000 muertos",
caption = "Fuente: Wikipedia")
bar1= bar1 + theme(axis.text.x =
element_text(angle = 60,#ANGULO
size=10,
hjust = 1))
bar1
#la moda de los paises
library(DescTools)
Mode(guerras$Location)
## [1] "China"
#HH pais
Herfindahl(table(guerras$Location))
## [1] 0.01850777
#(Laakso - Taagepera)
1/Herfindahl(table(guerras$Location))
## [1] 54.03137