This article describes how to take long-format aggregate data in your document and display that as a custom-built stacked area chart, like this:
Your data should be set up in a long format, with two numeric columns which will become the x and y axes of the chart, and one categorical column which will determine the categories the data is split by. See How to Create Long-Format Aggregated Data Using R (including the supplemental section) for more information on reshaping data into this structure.
Method 1 - a basic chart
1. Go to Calculation > Custom Calculation
2. Under Properties > R CODE enter code as follows:
# Load the ggplot2 function library
# Take an existing R Output or data frame called df which should be formatted as above.
data <- df
# Set up the plot itself and define where the data should come from. In the example here, the data
# for my x-axis is in column 1 of my data (x=data[,1]), the number of drinks in column 3 (y=data[,3]), and
# the categories in column 2 (fill=data[,2[).
plot = ggplot(data, aes(x=data[, 1], y=data[,3], fill=data[,2]))
# Print the plot to screen
plot + geom_area()
Method 2 - adding formatting
1. Take the same steps as above, but replace the last line of code with more advanced formatting options, eg, like this:
plot <- plot +
geom_area(colour="black", size=0.2, alpha=.8) +
labs(fill = "Age") +
ggtitle("Total Number of Cola Drinks had Jan to Dec") +
labs(x="Month", y="Sum of Cola Drinks had")
The above uses a range of options that are available when working with ggplot2. For more information on what these, see the official ggplot2 documentation