create_Pies: Create Pies

Description Usage Arguments Value See Also Examples

View source: R/Pies.R

Description

Generates pie charts that can be overlaid on maps. The Input data must be a dataframe with, at least, columns for latitude, longitude, class and value. For each location, a pie is created with pieces for each class, and the size of each piece depends on the proportion of each class (the value of each class divided by the sum of values). Optionally, the area of each pie can be proportional to a chosen variable (if that variable is different than the value mentioned above, the Input data must have a fifth column and that variable must be unique to each location). If the Input data contains locations that are too close together, the data can be gridded by setting GridKm Once pie charts have been created, the function add_PieLegend may be used to add a legend to the figure.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
create_Pies(
  Input,
  NamesIn = NULL,
  Classes = NULL,
  cols = c("green", "red"),
  Size = 50,
  SizeVar = NULL,
  GridKm = NULL,
  Other = 0,
  Othercol = "grey"
)

Arguments

Input

the name of the Input data as an R dataframe.

NamesIn

character vector of length 4 specifying the column names of Latitude, Longitude, Class and value fields in the Input.

Names must be given in that order, e.g.:

NamesIn=c('Latitude','Longitude','Class','Value').

Classes

optional character vector of classes to be displayed. If this excludes classes that are in the Input, those excluded classes will be polled in a 'Other' class.

cols

vector of two or more color names to colorize pie pieces.

Size

numeric value controlling the size of pies.

SizeVar

optional, name of the field in the Input that should be used to scale the area of pies. Must be unique to locations.

GridKm

optional, cell size of the grid in kilometers, if gridding is desired (in which case locations a pooled by grid cell and values are summed for each class).

Other

optional, percentage threshold below which classes are pooled in a 'Other' class.

Othercol

optional, color of the pie piece for the 'Other' class.

Value

Spatial object in your environment, ready to be plotted.

See Also

add_PieLegend, 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
 
#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.