Loon supports layering of visuals and groups of visuals. The
l_layer
function is a generic method.
l_layer(widget, x, ...)
layer object handle, layer id
widget path as a string or as an object handle
for UseMethod
: an object whose class will determine the method to be dispatched.
additional arguments, often state definition for the basic layering function
loon's displays that use the main graphics model (i.e. histogram, scatterplot and graph displays) support layering of visual information. The following table lists the layer types and functions for layering on a display.
Type | Description | Creator Function |
group | a group can be a parent of other layers | l_layer_group |
polygon | one polygon | l_layer_polygon |
text | one text string | l_layer_text |
line | one line (i.e. connected line segments) | l_layer_line |
rectangle | one rectangle | l_layer_rectangle |
oval | one oval | l_layer_oval |
points | n points (filled) circle | l_layer_points |
texts | n text strings | l_layer_text |
polygons | n polygons | l_layer_polygons |
rectangles | n rectangles | l_layer_rectangles |
lines | n sets of connected line segments | l_layer_lines |
smooth | fitted smooth line | l_layer_smooth |
rasterImage | one raster image | l_layer_rasterImage |
heatImage | one heat image | l_layer_heatImage |
contourLines | contour lines | l_layer_contourLines |
Every layer within a display has a unique id. The visuals of the data in a
display present the default layer of that display and has the layer id
'model'
. For example, the 'model'
layer of a scatterplot
display visualizes the scatterplot glyphs. Functions useful to query layers
are
Function | Description |
l_layer_ids | List layer ids |
l_layer_getType | Get layer type |
Layers are arranged in a tree structure with the tree root having the layer
id 'root'
. The rendering order of the layers is according to a
depth-first traversal of the layer tree. This tree also maintains a label
and a visibility flag for each layer. The layer tree, layer ids, layer
labels and the visibility of each layer are visualized in the layers
inspector. If a layer is set to be invisible then it is not rendered on the
display. If a group layer is set to be invisible then all its children are
not rendered; however, the visibility flag of the children layers remain
unchanged. Relevant functions are:
Function | Description |
l_layer_getParent | Get parent layer id of a layer |
l_layer_getChildren | Get children of a group layer |
l_layer_index | Get the order index of a layer among its siblings |
l_layer_printTree | Print out the layer tree |
l_layer_move | Move a layer |
l_layer_lower | Switch the layer place with its sibling to the right |
l_layer_raise | Switch the layer place with its sibling to the left |
l_layer_demote | Moves the layer up to be a left sibling of its parent |
l_layer_promote | Moves the layer to be a child of its right group layer sibling |
l_layer_hide | Set the
layers visibility flag to FALSE |
l_layer_show | Set the layers visibility flag to TRUE |
l_layer_isVisible | Return visibility flag of layer |
l_layer_layerVisibility | Returns logical value for whether layer is actually seen |
l_layer_groupVisibility | Returns all , part or none for expressing which
part of the layers children are visible. |
l_layer_delete | Delete a layer. If the layer is a group move all its children layers to the layers parent. |
l_layer_expunge | Delete layer and all its children layer. |
l_layer_getLabel | Get layer label. |
l_layer_relabel | Change layer label. |
l_layer_bbox | Get the bounding box of a layer. |
All layers have states that can be queried and modified using the same
functions as the ones used for displays (i.e. l_cget
,
l_configure
, `[`
and `[<-`
). The
last group of layer types in the above table have n-dimensional states,
where the actual value of n can be different for every layer in a display.
The difference between the model layer and the other layers is that the model layer has a selected state, responds to selection gestures and supports linking.
For more information run: l_help("learn_R_layer")
l_info_states
, l_scaleto_layer
, l_scaleto_world
;
some l_layer
S3 methods:
l_layer.density
, l_layer.map
,
l_layer.SpatialPolygonsDataFrame
, l_layer.SpatialPolygons
,
l_layer.Polygons
, l_layer.Polygon
, l_layer.SpatialLinesDataFrame
,
l_layer.SpatialLines
, l_layer.Lines
, l_layer.Line
,
l_layer.SpatialPointsDataFrame
, l_layer.SpatialPoints
if(interactive()){
# l_layer is a generic method
newFoo <- function(x, y, ...) {
r <- list(x=x, y=y, ...)
class(r) <- 'foo'
return(r)
}
l_layer.foo <- function(widget, x) {
x$widget <- widget
id <- do.call('l_layer_polygon', x)
return(id)
}
p <- l_plot()
obj <- newFoo(x=c(1:6,6:2), y=c(3,1,0,0,1,3,3,5,6,6,5), color='yellow')
id <- l_layer(p, obj)
l_scaleto_world(p)
}
Run the code above in your browser using DataLab