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
#load the libraries | |
library(ggplot2) | |
library(grid) | |
library(dplyr) | |
#load the data | |
#https://public.opendatasoft.com/explore/dataset/us-zip-code-latitude-and-longitude/export/ | |
zips <- | |
read.csv("us-zip-code-latitude-and-longitude.csv", | |
header = TRUE, stringsAsFactors = TRUE,sep=";") |
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
```{r} | |
library(dplyr) | |
library(readr) | |
library(ggplot2) # devtools::install_github("hadley/ggplot2") | |
#library(hrbrmisc) # devtools::install_github("hrbrmstr/hrbrmisc") | |
library(grid) | |
library(scales) | |
library(grid) |
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
Now start with maps and locations | |
See if i can get the center of constituencies | |
data from https://geoportal.statistics.gov.uk/datasets/westminster-parliamentary-constituencies-december-2017-super-generalised-clipped-boundaries-in-the-uk/data | |
```{r} | |
locat<-read_csv("Westminster_Parliamentary_Constituencies_December_2017_Super_Generalised_Clipped_Boundaries_in_the_UK.csv")#, sheet = 2, skip=6 , header=TRUE | |
head(locat) |
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
--- | |
title: "uk election" | |
output: html_notebook | |
--- | |
Inspired by this great graph by Alasdair Rae | |
https://twitter.com/undertheraedar/status/1190192038274310144 i want to make an election visualisation | |
data from https://commonslibrary.parliament.uk/parliament-and-elections/elections-elections/constituency-data-election-results/ | |
```{r} |
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
yyyy | mm | tmax | tmin | af | rain | sun | |
---|---|---|---|---|---|---|---|
1853 | 1 | NA | NA | NA | 57.3 | NA | |
1853 | 2 | NA | NA | NA | 32.3 | NA | |
1853 | 3 | NA | NA | NA | 65.5 | NA | |
1853 | 4 | NA | NA | NA | 46.2 | NA | |
1853 | 5 | NA | NA | NA | 13.2 | NA | |
1853 | 6 | NA | NA | NA | 53.3 | NA | |
1853 | 7 | NA | NA | NA | 78.0 | NA | |
1853 | 8 | NA | NA | NA | 56.6 | NA | |
1853 | 9 | NA | NA | NA | 24.5 | NA |
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
library(tidyverse) | |
money <- read.csv("NS_Table_3_1a_1617.csv",skip = 5, header = T, nrows = 100, dec=",") | |
#, nrows = 1, | |
money <- money[-1,] | |
money<-select (money,-c(X,X.1,X.2,X.3,X.4,X.5,X.6,X.7,X.8,X2008.09..a.)) | |
#money<-as.numeric(sub(",", ".", money)) | |
money$Percentile.point <- as.integer(money$Percentile.point) | |
#money <- money[order(money$Percentile.point), ] | |
head(money) | |
#make an id row |
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
elect <- read.csv("ElectionsUk.csv", header = TRUE) | |
#turn this format into a date | |
library(lubridate) | |
elect$date2 <- dmy(elect$date) | |
p <- ggplot(elect,aes(x = date2, y = Millions.of.Votes)) +#, colour = elect$Type | |
geom_point(aes(colour = Type), | |
shape=21, | |
fill= "White", |
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
library(eurostat) # eurostat data | |
library(rnaturalearth) # worldwide map data | |
library(tidyverse) # tidy data transformation | |
library(lubridate) # date and time support | |
library(sf) # simple features GIS | |
library(RColorBrewer) | |
euro_pop <- | |
get_eurostat('demo_r_pjanaggr3', stringsAsFactors = FALSE) %>% |
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
#The start of this file is from https://www.reddit.com/r/CodingHelp/comments/9jguwj/help_with_python_data_analsyis/ | |
#Specifically David Kopp http://www.cis.umassd.edu/~dkoop/ where he ingets the noaa data | |
import os | |
from urllib.request import urlretrieve | |
# download the data if we don't have it locally | |
url = "https://www.nhc.noaa.gov/data/hurdat/hurdat2-1851-2017-050118.txt" | |
local_fname = "hurdat2.txt" | |
if not os.path.exists("hurdat2.txt"): | |
urlretrieve(url, local_fname) |
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
eur<-read_csv('GEOSTAT_grid_POP_1K_2011_V2_0_1.csv') | |
#two ways to extract east and north | |
eur$North <-str_match(eur$GRD_ID, "1kmN(\\d\\d\\d\\d)E(\\d\\d\\d\\d)")[,2] | |
eur$East <-str_match(eur$GRD_ID, "1kmN(\\d\\d\\d\\d)E(\\d\\d\\d\\d)")[,3] | |
eur<-eur%>% | |
mutate( | |
lat = as.numeric(gsub('.*N([0-9]+)[EW].*', '\\1', GRD_ID))/100, | |
lng = as.numeric(gsub('.*[EW]([0-9]+)', '\\1', GRD_ID)) * ifelse(gsub('.*([EW]).*', '\\1', GRD_ID) == 'W', -1, 1) / 100 | |
) |