File:Comparación Partido-Radical Democracia-Cristiana Votos Parlamentarios.png

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file(3,000 × 1,800 pixels, file size: 160 KB, MIME type: image/png)

Captions

Captions

Add a one-line explanation of what this file represents

Summary[edit]

Description
English: Comparison between the Deputies vote rate of Radical Party of Chile and Christian Democratic Party
Date
Source Own work
Author TomásDanke

Código en lenguaje R:

        1. Paquetes utilizados####

library(tidyverse) library(rvest) library(rlist) library(stringi) library(htmltab) library(qdap) library(Cairo)

        1. Partido Radical####
  1. Escrap

url_pr <- 'https://es.wikipedia.org/wiki/Partido_Radical_de_Chile'

elecciones_pr <- url_pr %>% read_html() %>% html_node(xpath = '//*[@id="mw-content-text"]/div/table[3]') %>% html_table(fill = TRUE)

  1. Arreglo la base

elecciones_pr <- elecciones_pr[,c(1,2,3)] elecciones_pr$Elección <- as.numeric(elecciones_pr$Elección) elecciones_pr$Elección[is.na(elecciones_pr$Elección)] <- 0

elecciones_pr <- elecciones_pr %>% rename(Votos = Diputados,

                        P.votos = Diputados.1) %>% 
 filter(Elección!=0)
 
 

elecciones_pr$P.votos <- gsub(",",".", elecciones_pr$P.votos) elecciones_pr$P.votos <- gsub("%","", elecciones_pr$P.votos) elecciones_pr$P.votos <- gsub("space:", "", elecciones_pr$P.votos) elecciones_pr$P.votos <- as.numeric(elecciones_pr$P.votos)

elecciones_pr$Votos <- as.character(elecciones_pr$Votos) elecciones_pr$Votos <- gsub("\u200b", "", elecciones_pr$Votos) elecciones_pr$Votos <- genX(elecciones_pr$Votos, "[", "]") elecciones_pr$Votos <- gsub("space:", "", elecciones_pr$Votos) elecciones_pr$Votos <- as.numeric(elecciones_pr$Votos)

        1. Partido Demócrata Cristiano####
  1. Escrap

url_dc <- 'https://es.wikipedia.org/wiki/Partido_Dem%C3%B3crata_Cristiano_(Chile)'

elecciones_dc <- url_dc %>%

 read_html() %>%
 html_node(xpath = '//*[@id="mw-content-text"]/div/table[7]') %>%
 html_table(fill = TRUE)
  1. Arreglo la base

elecciones_dc <- elecciones_dc[,c(1,2,3)] elecciones_dc$Elección <- as.numeric(elecciones_dc$Elección) elecciones_dc$Elección[is.na(elecciones_dc$Elección)] <- 0 elecciones_dc <- elecciones_dc %>% rename(Votos = Diputados,

                                         P.votos = Diputados.1) %>% 
 filter(Elección!=0)

elecciones_dc$P.votos <- gsub(",",".", elecciones_dc$P.votos) elecciones_dc$P.votos <- gsub("%","", elecciones_dc$P.votos) elecciones_dc$P.votos <- gsub("space:", "", elecciones_dc$P.votos) elecciones_dc$P.votos <- as.numeric(elecciones_dc$P.votos)

elecciones_dc$Votos <- as.character(elecciones_dc$Votos) elecciones_dc$Votos <- gsub("\u200b", "", elecciones_dc$Votos) elecciones_dc$Votos <- genX(elecciones_dc$Votos, "[", "]") elecciones_dc$Votos <- gsub("space:", "", elecciones_dc$Votos) elecciones_dc$Votos <- as.numeric(elecciones_dc$Votos)

        1. Ambos####

elecciones_pr$Partido <- rep("Partido Radical", nrow(elecciones_pr))

elecciones_dc$Partido <- rep("Partido Demócrata Cristiano",

                            nrow(elecciones_dc))

elecciones_2partidos <- rbind(elecciones_pr,

                             elecciones_dc)
  1. Gráfico

CairoWin()

plot_final <- elecciones_2partidos %>%

 ggplot( aes(x=Elección, y=P.votos, colour=Partido)) +
 geom_line() +
 geom_point() +
 labs(x = "Año de la elección", y = "Porcentaje de votos parlamentarios",
      caption = "Fuente: Wikipedia") +
 scale_x_continuous(breaks = c(seq(1891, 1924, by=3),
                               1925, 1932, 
                               seq(1937, 1973, by=4),
                               seq(1989, 2017, by=4))) + 
 scale_y_continuous(breaks = c(seq(0,50,by=5)))+
 scale_color_manual(values=c("blue1","red1")) +
 theme_light() +
 theme(text = element_text(size=7, family = "TT Arial"), 
 axis.text.x = element_text(angle=90, hjust=1))

Licensing[edit]

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current21:48, 4 July 2020Thumbnail for version as of 21:48, 4 July 20203,000 × 1,800 (160 KB)TomásDanke (talk | contribs)Uploaded own work with UploadWizard

There are no pages that use this file.

Metadata