add_PieLegend: Add a legend to Pies

Description Usage Arguments Value See Also Examples

View source: R/Pies.R

Description

Adds a legend to pies created using create_Pies.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
add_PieLegend(
  Pies = NULL,
  PosX = 0,
  PosY = 0,
  Size = 25,
  lwd = 1,
  Boxexp = c(0.2, 0.2, 0.12, 0.3),
  Boxbd = "white",
  Boxlwd = 1,
  Labexp = 0.3,
  fontsize = 1,
  LegSp = 0.5,
  Horiz = TRUE,
  PieTitle = "Pie chart",
  SizeTitle = "Size chart",
  PieTitleVadj = 0.5,
  SizeTitleVadj = 0.3,
  nSizes = 3,
  SizeClasses = NULL
)

Arguments

Pies

Spatial object created using create_Pies.

PosX

numeric, horizontal adjustment of legend.

PosY

numeric, vertical adjustment of legend.

Size

numeric value controlling the size of pies.

lwd

numeric value controlling the line thickness of pies.

Boxexp

numeric vector of length 4 controlling the expansion of the legend box, given as c(xmin,xmax,ymin,ymax).

Boxbd

color of the background of the legend box.

Boxlwd

numeric value controlling the line thickness of the legend box.

Labexp

numeric value controlling the distance of the pie labels to the center of the pie.

fontsize

Size of the legend font.

LegSp

Numeric, spacing between the pie and the size chart (only used if SizeVar was specified in create_Pies).

Horiz

Logical. Set to FALSE if vertical layout is desired (only used if SizeVar was specified in create_Pies).

PieTitle

Character, title of the pie chart.

SizeTitle

Character, title of the size chart (only used if SizeVar was specified in create_Pies).

PieTitleVadj

numeric value controlling the vertical adjustment of the title of the pie chart.

SizeTitleVadj

numeric value controlling the vertical adjustment of the title of the size chart (only used if SizeVar was specified in create_Pies).

nSizes

integer, number of size classes to display in the size chart. Minimum and maximum sizes are displayed by default. (only used if SizeVar was specified in create_Pies).

SizeClasses

numeric vector (e.g. c(1,10,100)) to select the size classes to display in the size chart (only used if SizeVar was specified in create_Pies). If set, overrides nSizes.

Value

Adds a legend to a pre-existing plot.

See Also

create_Pies, PieData, PieData2.

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
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#Example 1. Pies of constant size, all classes displayed:
#Create pies
MyPies=create_Pies(Input=PieData,
                   NamesIn=c("Lat","Lon","Sp","N"),
                   Size=50
                   )
#Plot Pies
plot(MyPies,col=MyPies$col)
#Add Pies legend
add_PieLegend(Pies=MyPies,PosX=-0.1,PosY=-1,Boxexp=c(0.5,0.45,0.12,0.45),
             PieTitle="Species")


#Example 2. Pies of constant size, selected classes displayed:
#Create pies
MyPies=create_Pies(Input=PieData,
                   NamesIn=c("Lat","Lon","Sp","N"),
                   Size=50,
                   Classes=c("TOP","TOA","ANI")
                   )
#Plot Pies
plot(MyPies,col=MyPies$col)
#Add Pies legend
add_PieLegend(Pies=MyPies,PosX=-0.1,PosY=-1,Boxexp=c(0.6,0.6,0.12,0.55),
              PieTitle="Selected species")


#Example 3. Pies of constant size, proportions below 25% are grouped in a 'Other' class
#(N.B.: unlike Example 2, the 'Other' class may contain classes that are displayed in the legend.
#Please compare Example 1 and Example 3)
#Create pies
MyPies=create_Pies(Input=PieData,
                   NamesIn=c("Lat","Lon","Sp","N"),
                   Size=50,
                   Other=25
                   )
#Plot Pies
plot(MyPies,col=MyPies$col)
#Add Pies legend
add_PieLegend(Pies=MyPies,PosX=-0.1,PosY=-1,Boxexp=c(0.55,0.55,0.12,0.45),
              PieTitle="Other (%) class")


#Example 4. Pies of variable size (here, their area is proportional to 'Catch'),
#all classes displayed, horizontal legend:
#Create pies
MyPies=create_Pies(Input=PieData,
                   NamesIn=c("Lat","Lon","Sp","N"),
                   Size=18,
                   SizeVar="Catch"
                   )
#Plot Pies
plot(MyPies,col=MyPies$col)
#Add Pies legend
add_PieLegend(Pies=MyPies,PosX=-0.3,PosY=-0.8,Boxexp=c(0.16,0.1,0.1,0.4),
              PieTitle="Species",SizeTitle="Catch (t.)")


#Example 5. Pies of variable size (here, their area is proportional to 'Catch'),
#all classes displayed, vertical legend:
#Create pies
MyPies=create_Pies(Input=PieData,
                   NamesIn=c("Lat","Lon","Sp","N"),
                   Size=18,
                   SizeVar="Catch"
                   )
#Plot Pies
plot(MyPies,col=MyPies$col)
#Add Pies legend
add_PieLegend(Pies=MyPies,PosX=-1.7,PosY=0.1,Boxexp=c(0.35,0.32,0.02,0.15),
              PieTitle="Species",SizeTitle="Catch (t.)",Horiz=FALSE,LegSp=0.6)


#Example 6. Pies of constant size, all classes displayed.
#Too many pies (see next example for solution):
#Create pies
MyPies=create_Pies(Input=PieData2,
                   NamesIn=c("Lat","Lon","Sp","N"),
                   Size=5
                   )
#Plot Pies
plot(MyPies,col=MyPies$col)
#Add Pies legend
add_PieLegend(Pies=MyPies,PosX=-0.8,PosY=-0.1,Boxexp=c(0.5,0.45,0.12,0.45),
              PieTitle="Species")


#Example 7. Pies of constant size, all classes displayed. Gridded locations (in which case numerical
#variables in the 'Input' are summed for each grid point):
#Create pies
MyPies=create_Pies(Input=PieData2,
                   NamesIn=c("Lat","Lon","Sp","N"),
                   Size=5,
                   GridKm=250
                   )
#Plot Pies
plot(MyPies,col=MyPies$col)
#Add Pies legend
add_PieLegend(Pies=MyPies,PosX=-0.8,PosY=-0.1,Boxexp=c(0.5,0.45,0.12,0.45),
              PieTitle="Species")


#Example 8. Pies of variable size (here, their area is proportional to 'Catch'),
#all classes displayed, vertical legend, gridded locations (in which case numerical
#variables in the 'Input' are summed for each grid point):
MyPies=create_Pies(Input=PieData2,
                   NamesIn=c("Lat","Lon","Sp","N"),
                   Size=3,
                   GridKm=250,
                   SizeVar='Catch'
                   )
#Plot Pies
plot(MyPies,col=MyPies$col)
#Add Pies legend
add_PieLegend(Pies=MyPies,PosX=-1.2,PosY=0.3,Boxexp=c(0.38,0.32,0.08,0.18),
              PieTitle="Species",Horiz=FALSE,SizeTitle="Catch (t.)",
              SizeTitleVadj=0.8,nSizes=2)

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