create_Pies {CCAMLRGIS} | R Documentation |
Create Pies
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
create_Pies(
Input,
NamesIn = NULL,
Classes = NULL,
cols = c("green", "red"),
Size = 50,
SizeVar = NULL,
GridKm = NULL,
Other = 0,
Othercol = "grey"
)
Arguments
Input |
input dataframe. |
NamesIn |
character vector of length 4 specifying the column names of Latitude, Longitude,
Class and value fields in the Names must be given in that order, e.g.:
|
Classes |
character, optional vector of classes to be displayed. If this excludes classes that are in the |
cols |
character, vector of two or more color names to colorize pie pieces. |
Size |
numeric, value controlling the size of pies. |
SizeVar |
numeric, optional, name of the field in the |
GridKm |
numeric, optional, cell size of the grid in kilometers. If provided, locations are pooled by grid cell and values are summed for each class. |
Other |
numeric, optional, percentage threshold below which classes are pooled in a 'Other' class. |
Othercol |
character, 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
# For more examples, see:
# https://github.com/ccamlr/CCAMLRGIS#23-create-pies
#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(st_geometry(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")