Difference between revisions of "Wikisym 2013 Demo"
From Testiwiki
Juha Villman (talk | contribs) (→Very basic example) |
Juha Villman (talk | contribs) (→Mapping buildings of Kuopio into GoogleMaps) |
||
Line 96: | Line 96: | ||
legend("topleft", legend=names(attr(colcode, "table")),title="Ika", fill=attr(colcode, "palette"), cex=1.0, bty="y",bg="white") | legend("topleft", legend=names(attr(colcode, "table")),title="Ika", fill=attr(colcode, "palette"), cex=1.0, bty="y",bg="white") | ||
+ | </rcode> | ||
+ | |||
+ | == Plot emissions == | ||
+ | |||
+ | <rcode embed=1 graphics=1 name='pm25_plot' variables="name:treshold|description:Treshold|default:0.001|name:kk|description:Month|default:4|type:selection|options:1;Jan;2;Feb;3;Mar;4;Apr;5;May;6;Jun;7;Jul;8;Aug;9;Sep;10;Oct;11;Nov;12;Dec| | ||
+ | name:pv|description:Day|default:1|type:selection|options:1;1;2;2;3;3;4;4;5;5;6;6;7;7;8;8;9;9;10;10;11;11;12;12;13;13;14;14;15;15;16;16;17;17;18;18;19;19;20;20;21;21;22;22;23;23;24;24;25;25;26;26;27;27;28;28;29;29;30;30;31;31"> | ||
+ | |||
+ | library(OpasnetUtils) | ||
+ | library(OpasnetUtilsExt) | ||
+ | library(rgdal) | ||
+ | library(maptools) | ||
+ | library(raster) | ||
+ | |||
+ | par(mfrow=c(6,1), mar=c(3,1,0,1), cex=1.5) | ||
+ | |||
+ | colorstrip <- function(colors, labels) | ||
+ | { | ||
+ | count <- length(colors) | ||
+ | m <- matrix(1:count, count, 1) | ||
+ | image(m, col=colors, ylab="", axes=FALSE) | ||
+ | axis(1,approx(c(0, 1), n=length(labels))$y, labels) | ||
+ | } | ||
+ | |||
+ | shp_o <- spatial_db_query(paste('SELECT * FROM metsapalot_pm2_5_europe_2006 WHERE pm2_5 > ',treshold,' AND kk = ',kk,' AND pv = ',pv,';',sep='')) | ||
+ | |||
+ | #THIS IS A KEY PART OF FILTER CODE: As you are calling in a Query you need to tell R what the Lat Lon attributes are of the data | ||
+ | coordinates(shp_o)=c("lon","lat") | ||
+ | |||
+ | #plotvar removed as points all same value -- in future we may need an 'IF' clause here | ||
+ | #all reference to colcode removed in this example | ||
+ | |||
+ | |||
+ | #proj <- CRS("+ellps=sphere +a=127.4 +e=0 +proj=stere +lat_0=90 +lon_0=-32 +lat_ts=60 +x_0=8 +y_0=110") | ||
+ | proj <- ("+init=epsg:4326") | ||
+ | epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") | ||
+ | proj4string(shp_o) <- proj | ||
+ | shp<-spTransform(shp_o,epsg4326String) | ||
+ | |||
+ | #Create blank raster | ||
+ | rast<-raster() | ||
+ | |||
+ | #Set raster extent to that of point data | ||
+ | extent(rast)<-extent(shp) | ||
+ | |||
+ | #Choose number of columns and rows | ||
+ | ncol(rast)<-max(shp$emep_i)*2 | ||
+ | nrow(rast)<-max(shp$emep_j)*2 | ||
+ | |||
+ | cat("<span style='font-size: 1.2em;font-weight:bold;'>Wild Fire PM 2.5 Emissions in Europe</span>\n") | ||
+ | |||
+ | #Rasterize point data | ||
+ | rast2<-rasterize(shp, rast, shp$pm2_5, fun=mean) | ||
+ | |||
+ | #max(shp$pm2_5) | ||
+ | #min(shp$pm2_5) | ||
+ | |||
+ | #colors <- rainbow(11,start=0,end=0.15) | ||
+ | |||
+ | steps <- round(min(shp$pm2_5)):round(max(shp$pm2_5)) | ||
+ | colors <- rainbow(length(steps), start=0, end=0.50) | ||
+ | |||
+ | colorstrip(colors, steps) | ||
+ | |||
+ | #Plot data | ||
+ | google.show_raster_on_maps(rast2, col=colors, style="height:300px; width:300px;") | ||
+ | |||
</rcode> | </rcode> | ||
Revision as of 10:30, 1 August 2013
This page is a variable.
The page identifier is Op_en6032 |
---|
Moderator:Juha Villman (see all) |
This page is a stub. You may improve it into a full page, and then a rating bar will appear here. |
Upload data
|
Contents
R examples
Very basic example
Parameter example
Mapping buildings of Kuopio into GoogleMaps
Plot emissions
Reading data from Opasnet Base to R
Opasnet Base Examples
Narcolepsy in Finland
Table2Base Examples
Obs | Year | Country | Participants |
---|---|---|---|
1 | 2010 | Poland | 700 |
2 | 2011 | USA | 800 |
3 | 2012 | Austria | 900 |
4 | 2013 | Hong Kong | 1000 |
Obs | Year | Country | Participants |
---|---|---|---|
1 | 2010 | Poland | 700 |
2 | 2011 | Israel | 800 |
3 | 2012 | USA | 900 |
4 | 2013 | Hong Kong | 1000 |