0

I have a very simple dataframe

> samplePiece
        time memory   pid
1 1597323990  79872 11369
2 1597323990  51088 11157
3 1597324320  87435 11369
4 1597324320  63542 11157

and I'm trying to draw a stacked lines graph

> ggplot(samplePiece, aes(x=time, y=memory, fill=pid)) + 
        geom_area(stat = "identity", position = "stack")

I tried different combination of geom_area parameters. But in every case result was the same.

but when I do, I get this error:

Error: Aesthetics can not vary with a ribbon

It works only if the pid is the same. But when I add another process to observations, I get this error.

How can I fix this? Or... what do I do wrong?

I'm asking this question because there

Konstantin Bodnia
  • 1,372
  • 3
  • 20
  • 43
  • Does this answer your question? [How to fix Error in f(...) : Aesthetics can not vary with a ribbon](https://stackoverflow.com/questions/57333161/how-to-fix-error-in-f-aesthetics-can-not-vary-with-a-ribbon) – pietrodito Apr 03 '23 at 10:13

2 Answers2

0

Aha... That's basically because my pid was numeric. Transforming it into character helped.

Konstantin Bodnia
  • 1,372
  • 3
  • 20
  • 43
0

In my case, it was more tricky. I had set an argument that varied for color in ggplot(aes(). The geom_ribbon() uses this argument by default, and produces this error. To avoid this issue, one can set color=NULL, as geom_ribbon(aes(color=NULL), or avoid placing the color argument in the ggplot() call to begin with.

CoderGuy123
  • 6,219
  • 5
  • 59
  • 89