-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewdatatransform.R
77 lines (58 loc) · 1.64 KB
/
newdatatransform.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
setwd("C:/users/konsta/desktop/tryermap")
options(stringsAsFactors=FALSE)
data = read.csv("kuntainvaki.csv", header = TRUE, stringsAsFactors = FALSE, sep=",")
colnames(data) = c("name", seq(1980,2012,1))
str(data)
###
library(foreign)
alat = read.dbf("Kunnatwgs.dbf")
alat$nimet_Kunt = as.character(alat$nimet_Kunt)
alat = alat[order(alat$text),]
###
data.frame(data$name,alat$nimet_Kunt)
data$name = alat$nimet_Kunt
###
#pinta = read.csv("K:/git/tryermap/050_vaerak_tau_104.csv",sep="\t",skip=3);pinta
#str(pinta)
#str(pinta[-1,-1])
#pinta = pinta[-1,-1]
#pinta = pinta[1:320,]
#colnames(pinta) = c("name",seq(1980,2012,1))
#
###
alat = read.csv("alat13.txt",sep="\t")
str(alat)
alat = alat[1:320,c(2,4)]
colnames(alat) = c("name","ala")
str(alat)
###
data.frame(alat$name,data$name)
tiheydet = data[,-1]/alat$ala
data2 = data
data2[,-1] = tiheydet
str(data2)
###
library(reshape2)
rdat = melt(data2, id.vars="name", variable.name="vuosi", value.name="tiheys")
rdat$vuosi = as.numeric(as.character(rdat$vuosi))
str(rdat)
###
library(rMaps)
options(RCHART_WIDTH = 900, RCHART_HEIGHT = 700)
maps = ichoropleth(tiheys~name, data = rdat, ncuts = 9, animate ='vuosi', map='Kunnatwgs')
maps$set(
geographyConfig = list(
dataUrl="https://dl.dropboxusercontent.com/u/36138080/suomnimikunnat.topojson"
),
scope = "Kunnatwgs",
setProjection = '#! function( element, options ) {
var projection, path;
projection = d3.geo.transverseMercator()
.rotate([-27,-65,0])
.scale(4000)
.translate([element.offsetWidth / 2, element.offsetHeight / 2]);
path = d3.geo.path().projection( projection );
return {path: path, projection: projection};
} !#'
)
maps