Created
August 22, 2016 21:24
-
-
Save pbiecek/30b5fc69d8cdbfcaf222fbf5158d7237 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pobierz dane | |
library("XML") | |
url <- "https://pl.wikipedia.org/wiki/Lista_pa%C5%84stw_%C5%9Bwiata_wed%C5%82ug_liczby_ludno%C5%9Bci" | |
file<-read_html(url) | |
tables <-html_nodes(file, "table") | |
table1 <- html_table(tables[1], fill = TRUE) | |
table1 <- table1[[1]] | |
table1 <- table1[table1[,1] != "–",] | |
table1 <- table1[-1,c(1,2,8)] | |
table1[1,2] = "Chiny" | |
table1[3,2] = "USA" | |
colnames(table1) <- c("Lp","CNT", "population") | |
table1[,3] <- as.numeric(gsub(table1[,3], pattern="[^0-9]", replacement="")) | |
url <- "http://sportowefakty.wp.pl/rio-2016/klasyfikacja-medalowa" | |
file<-read_html(url) | |
tables<-html_nodes(file, "table") | |
table2 <- html_table(tables[1], fill = TRUE) | |
table2 <- table2[[1]] | |
colnames(table2)[1:2] = c("Lp.RIO","CNT") | |
table_merged <- merge(table1, table2) | |
# Rysuj | |
library(rbokeh) | |
selected = table_merged[,c("Suma", "population", "CNT")] | |
selected[,2] <- round(selected[,2]/10^6,3) | |
colnames(selected) <- c("Medali", "Populacja", "Kraj") | |
selected$czy_Polska <- factor(selected$Kraj == "Polska") | |
figure(width = 660, height = 660, title="Populacja a liczba medali w RIO 2016") %>% | |
ly_points(x=Populacja, y=Medali, hover = selected, data=selected, color=czy_Polska, legend=FALSE)%>% | |
x_axis(log = TRUE, label="Populacja w milionach", use_scientific=FALSE) %>% | |
y_axis(log=TRUE, label="Sumaryczna liczba medali") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment