-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_data.R
117 lines (117 loc) · 4.16 KB
/
create_data.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
# # # library(foreign)
# # # ess <- read.dta("~/data/ess/integr_ed20_round6/ESS6e02.dta")
# # # save(ess, file="~/data/ess/integr_ed20_round6/ESS6e02.rda")
#
# # Load Ess data
# load("~/data/ess/integr_ed20_round6/ESS6e02.rda")
# #
# # tee GB's UK (jotta kartat pelaa)
# ess$cntry[ess$cntry == "GB"] <- "UK"
#
# #liitetään maiden suomenkieliset nimet ja regiimien nimet
# library(RCurl)
# GHurl <- getURL("https://raw.githubusercontent.com/muuankarski/data/master/world/countries_continents.csv")
# dat <- read.csv(text = GHurl)
# dat <- dat[!duplicated(dat[c("cCode2")]),]
# # tee GB's UK (jotta kartat pelaa)
# dat$cCode2 <- as.character(dat$cCode2)
# dat$cCode2[dat$cCode2 == "GB"] <- "UK"
# ess <- merge(ess,dat,
# by.x="cntry",
# by.y="cCode2",
# all.x=TRUE)
#
#
# # luottamus shinyn muuttujat
# ess_luottamus <- ess[c("cntry","idno","pweight",
# "trstprl","trstlgl","trstplc","trstplt","trstprt","trstep","trstun", # valtaan
# "ppltrst","pplfair","pplhlp", # toiseen ihmiseen
# "maa","ryhma1")]
#
# save(ess_luottamus, file="data/ess_luottamus.rda")
#
# # hyvinvointi shinyn muuttujat
# ess_hyvinvointi <- ess[c("cntry","idno","pweight","maa","ryhma1",
# "dngval","nhpftr","lotsgot","lfwrs","flclpla", # mikä fiilis asioiden tolasta
# "deaimpp", # Kuinka vaikeata tai helppoa Teidän on selvitä elä
# "health", # terveydentyila
# "happy", # kuinka onnellinen olette
# "stflife","stfeco","stfgov","stfdem", # tyytyväinen
# "stfedu","stfhlth", # palvelut
# "gincdif", # Valtiovallan pitäisi ryhtyä toimenpiteisiin tuloerojen vähentämiseksi?
# "plinsoc")] # huippua
#
#
# save(ess_hyvinvointi, file="data/ess_hyvinvointi.rda")
#
# arvot shinyn muuttujat
# ess_arvot <- ess[c("cntry","idno","pweight","maa","ryhma1",
# "imsmetn","imdfetn","impcntr", # mamu kuinka paljon
# "imbgeco",
# "imueclt",
# "imwbcnt",
# "freehms")] # homo
#
# save(ess_arvot, file="data/ess_arvot.rda")
#
#
#
# ## Maatason shapefilet!
#
# #load EU country shapefile from GISco
# download.file("http://epp.eurostat.ec.europa.eu/cache/GISCO/geodatafiles/CNTR_2010_60M_SH.zip",
# destfile="zipfile")
# unzip("zipfile")
# library(rgdal)
# # read into SpatialPolygonsDataFrame
# map <- readOGR(dsn = "./CNTR_2010_60M_SH/data", layer = "CNTR_RG_60M_2010")
# # shapen yksinkertaistus
# library(rgdal)
# sdata <- as.data.frame(map)
# sdata <- sdata[,1:7]
#
# shapefileSimple <- rgeos::gSimplify(spgeom=map, tol=0.0060)
# map <- SpatialPolygonsDataFrame(shapefileSimple, data=sdata)
#
# library(ggplot2)
# library(rgeos)
# map <- gBuffer(map, width=0, byid=TRUE)
# map$id <- rownames(map@data)
# map.points <- fortify(map, region = "id")
# map.df <- merge(map.points, map, by = "id")
# # valitse vaan ne maat, jotka ovat ESS datassa
# ess_maat <- as.character(levels(factor(ess$cntry)))
# map.df <- map.df[map.df$CNTR_ID %in% ess_maat,]
#
# save(map.df, file="data/map.df.rda")
#
#
# ## Aluetason shapefile
#
#
# #load EU country shapefile from GISco
# download.file("http://epp.eurostat.ec.europa.eu/cache/GISCO/geodatafiles/NUTS_2010_60M_SH.zip",
# destfile="zipfile")
# unzip("zipfile")
# library(rgdal)
# # read into SpatialPolygonsDataFrame
# map <- readOGR(dsn = "./NUTS_2010_60M_SH/data", layer = "NUTS_RG_60M_2010")
# # shapen yksinkertaistus
# library(rgdal)
# sdata <- as.data.frame(map)
# #sdata <- sdata[,1:7]
#
# shapefileSimple <- rgeos::gSimplify(spgeom=map, tol=0.0055)
# map <- SpatialPolygonsDataFrame(shapefileSimple, data=sdata)
#
# library(ggplot2)
# library(rgeos)
# map <- gBuffer(map, width=0, byid=TRUE)
# map$id <- rownames(map@data)
# map.points <- fortify(map, region = "id")
# map.df <- merge(map.points, map, by = "id")
# # valitse vaan ne maat, jotka ovat ESS datassa
# #ess_maat <- as.character(levels(factor(ess$cntry)))
# map.df <- map.df[map.df$CNTR_ID %in% ess_maat,]
#
# save(map.df, file="data/map.df.nuts.rda")