add_Cscale {CCAMLRGIS} | R Documentation |
Add a color scale
Description
Adds a color scale to plots. Default behavior set for bathymetry. May also be used to
place a legend
.
Usage
add_Cscale(
pos = "1/1",
title = "Depth (m)",
width = 18,
height = 70,
cuts = Depth_cuts,
cols = Depth_cols,
minVal = NA,
maxVal = NA,
fontsize = 1,
offset = 100,
lwd = 1,
Titlefontsize = 1.2 * fontsize,
TitleVAdj = 0,
BoxAdj = c(0, 0, 0, 0),
BoxCol = "black",
BoxBG = "white",
Clwd = 0,
Ccol = "black",
Cwdth = 1,
TckL = 1,
Tcklwd = 1,
Tdist = 1,
mode = "Cscale"
)
Arguments
pos |
character, fraction indicating the vertical position of the color scale (which, by default, is on the
right side of plots). if |
title |
character, title of the color scale. |
width |
numeric, width of the color scale box, expressed in % of the width of the plotting region. |
height |
numeric, height of the color scale box, expressed in % of the height of the plotting region. |
cuts |
numeric, vector of color classes. May be generated via |
cols |
character, vector of color names. May be generated via |
minVal |
numeric, if desired, the color scale may be generated starting from the value |
maxVal |
numeric, if desired, the color scale may be generated up to the value |
fontsize |
numeric, size of the text in the color scale. |
offset |
numeric, controls the horizontal position of the color scale. |
lwd |
numeric, thickness of lines. |
Titlefontsize |
numeric, size of the title text. |
TitleVAdj |
numeric, vertical adjustment of the title. |
BoxAdj |
numeric vector of 4 values to adjust the sides of the box, given as |
BoxCol |
Color of the legend box frame. |
BoxBG |
Color of the legend box background. |
Clwd |
numeric, thickness of lines of cells. |
Ccol |
character, color of lines of cells, set to NA for no border. |
Cwdth |
numeric, positive factor to adjust the width of cells. |
TckL |
numeric, positive factor to adjust the length of tick lines. |
Tcklwd |
numeric, thickness of tick lines. |
Tdist |
numeric, horizontal adjustment of labels text. |
mode |
character, if 'Cscale', the default, the function builds a color scale. if 'Legend', the function
gives you the location of a |
See Also
load_Bathy
, SmallBathy
, Depth_cuts
, Depth_cols
,
Depth_cuts2
, Depth_cols2
, add_col
, add_Legend
,
R colors, legend
.
Examples
# For more examples, see:
# https://github.com/ccamlr/CCAMLRGIS#5-adding-colors-legends-and-labels
library(terra)
#Example 1: Adding two color scales
plot(SmallBathy(),breaks=Depth_cuts,col=Depth_cols,legend=FALSE,axes=FALSE,box=FALSE)
add_Cscale(pos='1/2',height=45,maxVal=0,minVal=-4000,fontsize=0.8)
#Some gridded data
MyGrid=create_PolyGrids(GridData,dlon=2,dlat=1)
Gridcol=add_col(MyGrid$Catch_sum,cuts=10)
plot(st_geometry(MyGrid),col=Gridcol$varcol,add=TRUE)
#Add color scale using cuts and cols generated by add_col, note the use of 'round'
add_Cscale(pos='2/2',height=45,title='Catch (t)',
cuts=round(Gridcol$cuts,1),cols=Gridcol$cols,fontsize=0.8)
#Example 2: Adding a color scale and a legend
#Create some point data
MyPoints=create_Points(PointData)
#Crop the bathymetry to match the extent of MyPoints
BathyCr=crop(SmallBathy(),extend(ext(MyPoints),100000))
plot(BathyCr,breaks=Depth_cuts,col=Depth_cols,legend=FALSE,axes=FALSE,mar=c(0,0,0,7))
add_Cscale(pos='1/2',height=45,maxVal=0,minVal=-4000,fontsize=0.8)
#Plot points with different symbols and colors (see ?points)
Psymbols=c(21,22,23,24)
Pcolors=c('red','green','blue','yellow')
plot(st_geometry(MyPoints[MyPoints$name=='one',]),pch=Psymbols[1],bg=Pcolors[1],add=TRUE)
plot(st_geometry(MyPoints[MyPoints$name=='two',]),pch=Psymbols[2],bg=Pcolors[2],add=TRUE)
plot(st_geometry(MyPoints[MyPoints$name=='three',]),pch=Psymbols[3],bg=Pcolors[3],add=TRUE)
plot(st_geometry(MyPoints[MyPoints$name=='four',]),pch=Psymbols[4],bg=Pcolors[4],add=TRUE)
#Add legend with position determined by add_Cscale
Loc=add_Cscale(pos='2/2',height=45,mode='Legend')
legend(Loc,legend=c('one','two','three','four'),title='Vessel',pch=Psymbols,
pt.bg=Pcolors,xpd=TRUE)