How to annotate only one graph/individual graphs

I have the following code:
ggplot(penguins)+geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, color=species))+
labs(title = "Mass vs. Length", subtitle = "Sample of Penguin dataset", caption = "Collected by Dr. Gorman")+
theme_classic()+xlab("Flipper Length")+ylab("Body Mass")+facet_wrap(.~species) +annotate("text", x=200,y=3500, label="Gentoo is the best", color="cornflowerblue", angle=30)

The data referrers to "palmerspenguins" package. I know that annotate() function writes for every individual chart but I want that text to be specifically for the graph where Gentoo is displayed.

Try this:

### Adapted from https://r-graphics.org/recipe-annotate-facet

library(tidyverse)
library(palmerpenguins)

birds  <- ggplot(penguins) +
  geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species)) +
  labs(title = "Mass vs. Length", subtitle = "Sample of Penguin dataset", caption = "Collected by Dr. Gorman") +
  theme_classic() +
  xlab("Flipper Length") +
  ylab("Body Mass") +
  facet_wrap(. ~ species)

p_labs <- data.frame(species  = c("Adelie", "Chinstrap", "Gentoo"), label = c(" ", " ", "Gentoo is best"))

 birds + geom_text(x = 200, y = 4500, aes(label = label), data = p_labs, angle = 30)


1 Like

It works, thank you!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.