Difference between revisions of "OpasnetUtils/Drafts"

From Testiwiki
Jump to: navigation, search
(Answer)
(Answer: MyPlotKML moved here)
Line 320: Line 320:
 
}
 
}
  
objects.store(ograph, fillna, collapsemarg, MyPointKML, ova2spat, MyRmap)
+
MyPlotKML <- function(
 +
shp, # a SpatialPointDataFrame object.
 +
result = "Result", # The name of  result column in shp.
 +
rasterization = TRUE, # Whether to rasterize the data or not.
 +
ncols = 32, # Number or columns in the raster.
 +
nrows = 32, # Number of rows in the raster.
 +
fun = mean # function to aggregate data points to the raster.
 +
) {
  
cat("The following objects are stored: ograph, fillna, collapsemarg, MyPointKML, ova2spat, MyRmap.\n")
+
cat("Consider merging this function MyPolotKML with google.show_raster_on_maps in OpasnetUtilsExt.\n")
 +
 
 +
if(rasterization) {
 +
#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) <- ncols
 +
nrow(rast) <- nrows
 +
 
 +
#Rasterize point data
 +
rast2 <- rasterize(shp, rast, shp[[result]], fun = fun)
 +
 
 +
}
 +
 
 +
start <- 0 # min(shp[[result]])
 +
end <- max(shp[[result]])
 +
steps <- approx(c(start,end),n=6)$y
 +
colors <- rev(rainbow(length(steps), start=0, end=0.50))
 +
 
 +
# Create the colorstrip below the map.
 +
 
 +
par(mfrow=c(6,1), mar=c(3,1,0,1), cex = 1.5)
 +
 
 +
colorstrip <- function(colors, labels)
 +
{
 +
count <- length(colors)
 +
image(
 +
matrix(1:count, count, 1),
 +
col = colors,
 +
ylab = "",
 +
axes = FALSE
 +
)
 +
axis(1,approx(c(0, 1), n=length(labels))$y, labels)
 +
}
 +
 
 +
colorstrip(colors, steps)
 +
 
 +
#Plot data
 +
 
 +
google.show_raster_on_maps(rast2, col = colors, style = "height:500px;")
 +
}
 +
 
 +
objects.store(ograph, fillna, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML)
 +
 
 +
cat("The following objects are stored: ograph, fillna, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML.\n")
  
 
</rcode>
 
</rcode>

Revision as of 06:55, 26 December 2013



Question

Which functions are so useful that they should be taken into OpasnetUtils package? This page contains draft function which will be included when they are good enough and found important.

Answer

+ Show code

See also

References


Related files

<mfanonymousfilelist></mfanonymousfilelist>