2

I am trying to plot the plot the data of three constituents on the same plot using ggplot. Specifically, I am trying to get a stacked line/area plot that represents the data distribution. The three constituents each have 451 values, hence why I have put the runif value as 451.

The code I am using is:

library(dplyr)
library(ggplot2)

cdom <- t(as.matrix(read.csv("CDOM.csv")))

abcoef <- as.numeric(cdom[2,], cdom[3,], cdom[4,], times=3)
wavelength <- as.numeric(cdom[1,], each=3)
value <- runif(451, -1, 1)
data <- data.frame(abcoef,wavelength,value)

ggplot(data, aes(x=wavelength, y=value, fill=abcoef)) + 
geom_area()

However, every time I try and run the code I get the code:

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

I have tried multiple methods of trying to derive the plot, but every format is resulting in the same error message. Any help would be great!

  • 4
    Please share a portion of your data, as `cdom` is not available for anybody who wants to help you – astrofunkswag Feb 28 '19 at 01:07
  • I think you've got some syntax errors.... you're giving arguments to `as.numeric()` as if it is `rep()`. Are you maybe missing some `rep()` calls in there? – Gregor Thomas Feb 28 '19 at 01:10
  • 1
    `ggplot(data, aes(x=wavelength, y=value, fill=factor(abcoef))) + geom_area()` – Ista Feb 28 '19 at 01:15

0 Answers0