Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

100% stacked area by groups

I have a dataset where

structure(list(product = structure(c(4L, 4L, 4L, 1L, 1L, 1L, 4L, 4L, 4L, 1L, 1L, 1L, 4L, 4L, 4L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 2L, 2L, 2L, 3L, 3L, 3L), .Label = c("C1", "C2", "C3", "Waste"), class = "factor"),
Machine = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("A", "B"), class = "factor"),  
subsample = c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L),  
Yield = c(9%, 3%, 0%, 91%, 97%, 100%, 3%, 1%, 0%, 97%, 99%, 100%, 14%, 5%, 0%, 25%, 15%, 1%, 61%, 80%, 99%, 13%, 6%, 1%, 24%, 18%, 6%, 64%, 76%, 94%)),  
class = "data.frame", row.names = c(NA, -30L))

What I need ultimately is something like this (the labeling is not important): graph created in excel and inkscape

The idea behind is to classify wood in different categories (products), which will depend on the quality of the subsample (1,2,3), but also the machine (A or B) used for the classification. I want to show how the amount of waste drops from the subsample 1 to 3, but there are also differences depending on the machine. One case is C1/Waste shown to the left. The case on the right can be read for machine A as: the amount of C2 varies between 61% and 99%, C3 between 25% and 1%, and what is not C2 or C3 is waste.

I tried to use the information in ggplot2 plotting a 100% stacked area chart, and 100% stacked area using ggplot and I tried

ggplot(example, aes(x = subsample, y = yield, fill = product)) +
  geom_area(position = position_fill()) +  facet_wrap(~ Machine)  +
  scale_fill_manual(values = c(Waste = "darkorange", Good = "slateblue", Superior = "slateblue"))

but it plots all the products together instead of making the combination C1/waste and C2/C3/waste. In addition, there are blank gaps. I wonder if I should include a new column specifying the combinations (C1/waste; C2/C3/waste)?

I have different combinations of products to plot so your help would be much appreciated.

Comments