Search code examples
rggplot2graphics

Showing Number of individuals used per graphic (ggplot2)


ive started using the R and the ggplot package recently, i would like to know if its possible to show in every graphic the number of individuals that my analysis is using and if yes, how i could do it?

im doing a biology study about a crab and his distribuition, in this graphic for example i used 24 individuals and i would like to show this on the graphic for better representation of the amostral amount like, "N = ?"


Solution

  • ggplot::annotate() will do that for you. For example:

    df <- data.frame(
      crab_id = 1:24,
      distribution = runif(24)
    )
    
    ggplot(df) +
      geom_histogram(aes(x = distribution), bins = 5)+
      annotate("text", x = 0.5, y = -.5, label = paste0("n = ", nrow(df)))