1

I was hoping someone might be able to help. I am still getting to grips with R and I am quite new to ggplot2.

My problem:

I am trying to make a stacked area plot. I have formatted my data frame so that it is in long format. My columns are Date, Category (filter.size) and value (chl.average).

e.g: data frame example

The issue I am having is that when I try and plot this, where Chlstacked is my data.frame):

stkchl <- ggplot(Chlstacked, aes(x=Date, y=chl.average,
fill=filter.size)) + geom_area()
stkchl

the axis and background layer plots but not the actual stack, although it recognises the categories in a legend with colours.

I have tried and alternate method:

stkchl <- ggplot(Chlstacked, aes(x=Date, y=chl.average))
stkchl      
stkchl + geom_area(aes(colour = chl.average, fill= chl.average),     
position = 'stack')

Which gives: Error in f(...) : Aesthetics can not vary with a ribbon

My thought is that perhaps as the Dates, which I would want on the x-axis (as it is time series), are repeated for each category (>20, <20>5, <5>GFF) they are not unique so maybe doing something - altough I am stumped as to what - to cause error.Or perhaps something simple that I am doing wrong within my coding?

Any help would be appreciated - thanks

Lmm
  • 403
  • 1
  • 6
  • 24
  • Hi, can you add the output of `dput(Chlstacked)` to your question to make the code reproducible? – J.Con Nov 30 '16 at 04:19
  • 1
    @J.Con I think I worked it out.... as normal with R it was a coding issue. I managed to get it to plot with: stkchl <- ggplot(Chlstacked, aes(x=Date, y=chl.average, group=filter.size, colour=filter.size, fill = filter.size)) + geom_area(stat= "identity") + ylab("Chl (µg/L)") + xlab("Date 2016 (dd-mm)") – Lmm Dec 01 '16 at 04:54
  • Hey, glad you figured it out. – J.Con Dec 06 '16 at 00:26

0 Answers0