panel_plot: Add graphical elements to the image panel

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

Standard fuctions for plotting from package graphics are used for manual adding elements to current plot. Theses series of functions used that standard instruments with additional controling the acceptability of plotting.

Usage

1
2
3
4
5
6
7
8
9

Arguments

obj

R object.

...

In panel_plot arguments are passed to function plot.
In panel_box arguments are passed to function box.
In panel_lines arguments are passed to function lines.
In panel_points arguments are passed to function points.
In panel_text arguments are passed to function text.
In panel_abline arguments are passed to function abline.
In panel_polygon arguments are passed to function polygon.
In panel_segments arguments are passed to function segments.

Details

If unable to get value TRUE from getOption("ursaPngPlot") then plotting is disable, and any function from this series returns NULL.

Generally, for spatial objects argument add=TRUE is used in panel_plot.

Value

For spatial objects (simple features from sf or spatial abstract classes from sp) function panel_plot returns object of class ursaLegend. It is a list with items, which can be used to as arguments of legend(). This is intermediate step for experimental feature (not ready) to display colorbars on plot panel. For other objects function panel_plot returns value of function plot.

Function panel_box returns value of function box.
Function panel_lines returns value of function lines.
Function panel_points returns value of function points.
Function panel_text returns value of function text.
Function panel_abline returns value of function abline.
Function panel_polygon returns value of function polygon.
Function panel_segments returns value of function segments.

Note

For plotted elements it is possible to create legend for colors using color bars. No shapes kind and size, no line widths.

To convert object x of class ursaLegend to object of class ursaColorTable please use ursa_colortable(x).

Author(s)

Nikita Platonov platonov@sevin.ru

See Also

panel_contour

Package graphics (help(package="graphics")) and functions plot, box, lines, points, text, abline, polygon, segments.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
session_grid(NULL)
require(rgdal)
a <- pixelsize()
g1 <- session_grid()
n <- 12L
k <- 5L
x <- with(g1,runif(n,min=minx,max=maxx))
y <- with(g1,runif(n,min=miny,max=maxy))
panel_plot(x,y) ## plots nothing, because 'compose_open(...,dev=F)' is not called yet
sl <- lapply(seq(k),function(id){
   x <- sort(with(g1,runif(n,min=minx,max=maxx)))
   y <- sort(with(g1,runif(n,min=miny,max=maxy)))
   sp::Lines(sp::Line(cbind(x,y)),ID=id)
})
sl <- sp::SpatialLines(sl,proj4string=sp::CRS(ursa_proj(g1)))#,id=length(sl))
lab <- t(sapply(sp::coordinates(sl),function(xy) xy[[1]][round(n/2),]))
lab <- as.data.frame(cbind(lab,z=seq(k)))
sl <- sp::SpatialLinesDataFrame(sl
              ,data=data.frame(ID=runif(k,min=5,max=9),desc=LETTERS[seq(k)]))
print(sl@data)
ct <- colorize(sl@data$ID)#,name=sldf@data$desc)
shpname <- tempfile(pattern = "___tmp",tmpdir=".",fileext=".shp")
layername <- gsub("\\.shp$","",basename(shpname))
try(writeOGR(sl,dirname(shpname),layername,driver="ESRI Shapefile"))
compose_open(layout=c(1,2),legend=list(list("bottom",2)))
panel_new()
panel_decor()
panel_lines(x,y,col="orange")
panel_points(x,y,cex=5,pch=21,col="transparent",bg="#00FF005F")
panel_points(0,0,pch=3)
panel_text(0,0,"North\nPole",pos=4,cex=1.5,family="Courier New",font=3)
panel_new()
panel_decor()
panel_plot(sl,lwd=4,col="grey20")
if (file.exists(shpname))
   panel_plot(shpname,lwd=3,col=ct$colortable[ct$index])
panel_points(lab$x,lab$y,pch=as.character(lab$z),cex=2)
compose_legend(ct$colortable)
compose_close()
file.remove(dir(path=dirname(shpname)
               ,pattern=paste0(layername,"\\.(cpg|dbf|prj|shp|shx)")
               ,full.names=TRUE))

ursa documentation built on May 23, 2021, 1:06 a.m.