Wikisym 2013 Demo: Difference between revisions
Jump to navigation
Jump to search
Juha Villman (talk | contribs) |
mNo edit summary |
||
(18 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
== Mapping buildings of Kuopio into GoogleMaps == | {{variable|stub="1"|moderator=Juha Villman}} | ||
[[Category:Contains R code]] | |||
== R examples == | |||
===Very basic example=== | |||
<rcode name="testing" embed='1'> | |||
a <-3 | |||
b <-4 | |||
a +b | |||
</rcode> | |||
===Parameter example=== | |||
<rcode name="tt" embed=1 variables="name:num1|description:Number 1|name:num2|description:Number 2"> | |||
sum <- num1 + num2 | |||
mul <- num1 * num2 | |||
cat(paste("<span style='font-size: 1.5em;font-weight:bold;'>Sum: ",sum,"</span>\n",sep='')) | |||
cat(paste("<span style='font-size: 1.5em;font-weight:bold;'>Mul: ",mul,"</span>\n",sep='')) | |||
</rcode> | |||
=== Mapping buildings of Kuopio into GoogleMaps === | |||
<rcode name='staticmapstest' graphics='1' embed='1'> | <rcode name='staticmapstest' graphics='1' embed='1'> | ||
Line 76: | Line 97: | ||
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> | |||
=== Reading data from Opasnet Base to R === | |||
<rcode name="opbase_read_test" > | |||
library("OpasnetUtils") | |||
library("xtable") | |||
# From opasnet | |||
thedata <- opbase.data("Op_en2949") | |||
print(xtable(thedata),type="html") | |||
</rcode> | </rcode> | ||
Line 82: | Line 181: | ||
=== Narcolepsy in Finland === | === Narcolepsy in Finland === | ||
* [[Population of Finland]] | |||
* [[Narcolepsy in Finland]] | * [[Narcolepsy in Finland]] | ||
== Table2Base Examples == | |||
<t2b name="WikiSym participants" index="Year,Country" unit="#" obs="Participants"> | |||
2010|Poland|700 | |||
2011|USA|800 | |||
2012|Austria|900 | |||
2013|Hong Kong|1000 | |||
</t2b> | |||
<t2b name="WikiMania participants" index="Year,Country" unit="#" obs="Participants"> | |||
2010|Poland|700 | |||
2011|Israel|800 | |||
2012|USA|900 | |||
2013|Hong Kong|1000 | |||
</t2b> | |||
== Upload example == | |||
* [[file:wikisym2013_upload_example.csv|Upload file example]] |
Latest revision as of 10:12, 26 August 2013
Moderator:Juha Villman (see all) |
This page is a stub. You may improve it into a full page. |
Upload data
|
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 |