add_Cscale: Add a color scale

Description Usage Arguments See Also Examples

View source: R/add_Cscale.R

Description

Adds a color scale to plots. Default behavior set for bathymetry. May also be used to place a legend.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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,
  mode = "Cscale"
)

Arguments

pos

character, indicating the vertical position of the color scale (which is always on the right side of plots). if pos="1/1", the color scale will be centered. if pos="1/2", the color scale will in the top half of the plotting regions. if pos="2/2", the color scale will in the bottom half of the plotting regions.

title

character, title of the color scale.

width

width of the color scale box, expressed in % of the width of the plotting region.

height

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 add_col.

cols

character vector of color names. May be generated via add_col.

minVal

If desired, the color scale may be generated starting from the value minVal. See examples.

maxVal

If desired, the color scale may be generated up to the value maxVal. See examples.

fontsize

Size of the text in the color scale.

offset

Controls the horizontal position of the color scale. Increase to distance from the plotting region.

lwd

thickness of lines.

mode

if 'Cscale', the default, the function builds a color scale. if 'Legend', the function gives you the location of a legend, arguments pos, offset and height may be used for adjustments. See examples.

See Also

load_Bathy, SmallBathy, Depth_cuts, Depth_cols, Depth_cuts2, Depth_cols2, add_col, R colors, legend.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#Example 1: simple bathymetry plot with color scale
Mypar=par(mai=c(0,0,0,1)) #plot margins as c(bottom, left, top, right)
plot(SmallBathy, breaks=Depth_cuts, col=Depth_cols, legend=FALSE,axes=FALSE,box=FALSE)
add_Cscale(height=95)
par(Mypar)

#' #Example 2: simple bathymetry plot with Fishable Depth range highlight and color scale
Mypar=par(mai=c(0,0,0,1)) #plot margins as c(bottom, left, top, right)
plot(SmallBathy, breaks=Depth_cuts2, col=Depth_cols2, legend=FALSE,axes=FALSE,box=FALSE)
add_Cscale(height=95,cuts=Depth_cuts2,cols=Depth_cols2)
par(Mypar)

#Example 3: Show only values greater than 'minVal'
Mypar=par(mai=c(0,0,0,1)) #plot margins as c(bottom, left, top, right),
plot(SmallBathy, breaks=Depth_cuts, col=Depth_cols, legend=FALSE,axes=FALSE,box=FALSE)
add_Cscale(minVal=-3200)
par(Mypar)

#Example 4: Show only values between 'minVal' and 'maxVal'
Mypar=par(mai=c(0,0,0,1)) #plot margins as c(bottom, left, top, right)
plot(SmallBathy, breaks=Depth_cuts, col=Depth_cols, legend=FALSE,axes=FALSE,box=FALSE)
add_Cscale(minVal=-3200,maxVal=-400)
par(Mypar)

#Example 5: Adding two color scales

#Bathymetry
Mypar=par(mai=c(0,0,0,1)) #plot margins as c(bottom, left, top, right)

plot(SmallBathy,breaks=Depth_cuts,col=Depth_cols,legend=FALSE,axes=FALSE,box=FALSE)
add_Cscale(pos='1/2',height=45,maxVal=-1,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(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)
par(Mypar)

#Example 6: Adding a color scale and a legend

#Create some point data
MyPoints=create_Points(PointData)

#Crop the bathymetry to match the extent of MyPoints (extended extent)
BathyCr=raster::crop(SmallBathy,raster::extend(raster::extent(MyPoints),100000))
Mypar=par(mai=c(0,0,0,1)) #plot margins as c(bottom, left, top, right)
plot(BathyCr,breaks=Depth_cuts,col=Depth_cols,legend=FALSE,axes=FALSE,box=FALSE)
add_Cscale(pos='1/2',height=45,maxVal=-1,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(MyPoints[MyPoints$name=='one',],pch=Psymbols[1],bg=Pcolors[1],add=TRUE)
plot(MyPoints[MyPoints$name=='two',],pch=Psymbols[2],bg=Pcolors[2],add=TRUE)
plot(MyPoints[MyPoints$name=='three',],pch=Psymbols[3],bg=Pcolors[3],add=TRUE)
plot(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)
par(Mypar)

CCAMLRGIS documentation built on Sept. 8, 2021, 9:09 a.m.