I have the dataset below:
eg_data <- data.frame(
time = c("1","2"),
size1=c(200, 300))
I add a row to the dataset that is a sum of both time periods:
eg_data <- rbind(eg_data, (data.frame(time="1 + 2",
size1=sum(eg_data$size1))))
eg_data$time <- factor(eg_data$time, levels = c("1 + 2", "1", "2"))
I create a bar graph
eg_data_bar <- (ggplot() +
geom_bar(data=eg_data, aes(y = size1, x = time, fill = time),
stat="identity",position='stack'))
eg_data_bar
As it stands now, the graph renders out as three bars which are different colors. I need the bar chart to render as three bars, period 1 is one color, period 2 is another color, and the grouped period 1 + 2 is made up of the two colors from period 1 and period 2.
The problem I'm having is how to define fill within the geom_bar(). When I've done stacked bars before, I always have a third column to use as the fill.
Any help is appreciated.
ggplot2
. – Maurits Evers