79624864

Date: 2025-05-16 09:19:36
Score: 0.5
Natty:
Report link

In case someone has the same headscratch as I did:

If you're doing a geom_line plot with facet_wrap and just one of the groups that your facetting with has an issue with the amount of data, you're going to get the message (ggplot 3.5.2)

`geom_line()`: Each group consists of only one observation.
ℹ Do you need to adjust the group aesthetic?

It took me a while to realize what was going on since I had a lot of groups and the plot looked mostly fine. The message concerns the panel which has only one observation. Simple example:

foo <- tibble(
  value = c(1:4,1:4,1),
  year = c(2001L:2004L, 2001L:2004L, 2002L),
  g = c(rep("G1", 4), rep("G2", 4), "G3")
)

ggplot(foo, aes(year, value)) +
  geom_line() +
  facet_wrap(~g)

A graph with three panels, of which the frist two show a simple line plot and the third has nothing.

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Probel