I want to do a pie chart. I have a table with column of age (pup, juvenile and adult) and another with harbours (Chichester and Langstone). Is it possible to do a pie chart for every harbour how is the place preference by age groups in percentage? Like pie chart Chicester harbour and there like 45% of juvenile and 15% of pups and 40% of adult.
r_seals.pdf (67.5 KB)
Here is whole the data set. I am not sure how to use the formula. Please, can you specify where I can put what? I am sorry I am just a beginner.
Take zdravim
It is technically possible to calculate the percentages in ggplot call, but it will not be very clear (nor beginner friendly).
I suggest you pre-calculate the summarisation first (i.e. outside of the ggplot) and then just add it via geom_text() with position = position_fill(vjust = 0.5) so that it is shown in the middle of the pie wedges.
Surely it is; consider something along the lines of this code (I am using only the first 4 rows of your seals dataset, as copying from pdf is a chore):
library(tidyverse)
seals <- data.frame(species = c("Harbour", "Harbour", "Harbour", "Harbour"),
ScarHuman = c(2, 2, 2, 3))
seals <- seals %>%
filter(species == "Harbour")
ggplot(seals, aes(x = ScarHuman)) +
geom_bar(fill = "firebrick") # the fill color is just for the looks