Ako vytváram grafy vývoja km ciest


v tabuľke fm_WaysStats máme uložené dáta. Stĺpec dátum je dátum ku ktorému je záznam, ostatné sú počty kilometrov.

span class="st0">`fm_WaysStats` (
  `datum``abandoned``bridleway``bus_guideway``canal``construction``crossing``cycleway``dam``disused``ditch``drain``FIXME``footwalk``footway``ford``fpath``highway``junction``living_street``mini_roundabout``monorail``motorway``motorway_link``narrow_gauge``path``pedestrian``platform``Pod``preserved``primary``primary_link``proposed``raceway``rail``residential``resil``river``riverbank``road``secondary``secondary_link``seri``service``station``steps``stream``subvay``tertiary``TOTAL``tr``track``tram``trunk``trunk_link``unclassified``undefined``unknown``unspecified``unsurfaced``weir``datum`



Samotné vytváranie grafov je pomocou programu R

library(DBI); library(RMySQL); con<-dbConnect(MySQL(),dbname='skwiki');

dd<-dbGetQuery(con, 'select datum from fm_WaysStats');
dates<-as.Date('2010-12-12')
for(i in 1:length(dd[,1])) dates[i] = as.Date(dd[i,]);

plotonly<-function(data,name='cesty', name2='cesty') {
	png(file=paste("images/stats-cesty-",name2,".png",sep=""), width=600, height=320);
	colnames<-names(data);
	if(max(data) > 4000000) { mult=1000000; jednotka='tisíce';}
	else {mult=1000; jednotka='';}
	par(mar=c(3,4,2,0));
	plot(dates,data[,colnames[1]], type='n', axes=FALSE,ylim=c(0,max(data)), ylab=paste('dĺžka ciest,',jednotka,'km'), main='Freemap.sk štatistiky Slovenska');
	colors<-rainbow(length(colnames));
	for(i in 1:length(colnames)) {
		lines(dates, data[,colnames[i]], col=colors[i]);
	}
	axis.Date(1,x=dates,at=seq(dates[1],max(dates), "months"), format="%b %y")
	ynum<-0;
	yat<-0;
	pocet=5;
	horny=round(max(data)/(pocet*mult))*pocet*mult;
	for(i in 1:pocet) {
		tt=round(horny*i/pocet);
		yat[i+1]<-tt;
		ynum[i+1]<-tt/mult;
	}
	axis(2, at=yat,labels=ynum )
	legend('topleft',colnames,col=colors,title=name,lwd=1);
	dev.off();
}

plottypes<-function(name, types, name2) {
	q<-paste('select `',paste(types, collapse='`,`'), '` from fm_WaysStats', sep='');
	data<-dbGetQuery(con, q);
	plotonly(data,name, name2);
	return(paste('`', paste(types,collapse='`+`'), '` as `',name, '`', sep=''));
}

plotsummary<-function(all) {
	q<-paste('select ',paste(all, collapse=','), ' from fm_WaysStats', sep='');
	data<-dbGetQuery(con,q);
	plotonly(data);
	return();
}
	
all<-c(
plottypes('lesné cesty',c('track','footway','path'),'lesne'),
plottypes('rýchlostné kom',c('motorway','motorway_link','trunk','trunk_link'),'rychlostne'),
plottypes('autá',c('primary','secondary','tertiary'), 'auta'),
plottypes('pešie',c('footway','pedestrian','path','steps'), 'pesie'),
plottypes('mesto',c('residential','service','unclassified','living_street'),'mesto')
);

plotsummary(all);

a<-plottypes('voda',c('river','stream','canal','dam','drain','weir','riverbank'),'voda');
a<-plottypes('železnice',c('tram','rail'),'zeleznice');

CategoryStats
There are no comments on this page.