I am trying to create a bar bar so that the x-axis is patients with each patient having multiple samples. So, for example, (using mtcars data as a template for how the data will look):
library("ggplot2") ggplot(mtcars, aes(x = factor(cyl), group = factor(gear))) + geom_bar(position = position_dodge(width = 0.8), binwidth = 25) + xlab("Patient") + ylab("Number of Mutations per Patient Sample")
This will create something like this:

With each line drawing representing the sample of each patient.
I want to add additional information about each patient sample, using colors to fill the haircuts (for example, different types of mutations in each patient sample). I thought I could specify the fill parameter as follows:
ggplot(mtcars, aes(x = factor(cyl), group = factor(gear), fill = factor(vs))) + geom_bar(position = position_dodge(width = 0.8), binwidth = 25) + xlab("Patient") + ylab("Number of Mutations per Patient Sample")
But this does not create "stacked haircuts" for each stroke pattern of the patient. I assume this is due to setting position_dodge (). Is there any way around this? Basically, I want:
ggplot(mtcars, aes(x = factor(cyl), fill = factor(vs))) + geom_bar() + xlab("Patient") + ylab("Number of Mutations per Patient Sample")

But these colors are available in the first plot that I listed. Is this possible with ggplot2?
source share