Various searches have led me to this solution which is not what I had envisioned but might work out better for me as I expand what I'm doing with the data.
Any other suggestions are still welcome!
library(ggplot2)
sampdata <-data.frame (Code = c('ab44c', 'ab55d', 'ab44c', 'ab55d', 'ab44c', 'ab55d', 'ab44c', 'ab55d', 'ab44c', 'ab55d', 'ab44c', 'ab55d'),
Desc = c('Shaft', 'Wheel', 'Shaft', 'Wheel', 'Shaft', 'Wheel', 'Shaft', 'Wheel', 'Shaft', 'Wheel', 'Shaft', 'Wheel'),
Month = c(202007, 202007, 202008, 202008, 202009, 202009, 202010, 202010, 202011, 202011, 202012, 202012),
Number = c(5, 45, 3, 23, 4, 89, 7, 2, 12, 88, 2, 47),
Cost = c(256.5, 1352.4, 153.9, 30.05, 205.2, 691.23, 359.1, 2674.75, 615.6, 60.11, 102.6, 2644.69)
)
# Calculate the total and store in a separate dataframe
samp2data <- sampdata %>% group_by(Month) %>% summarise(Total = sum(Cost))
# This plots the two dataframes together on the one chart.
# Note how they could have different plot types etc.
ggplot() +
geom_line(data = sampdata, aes(x = Month, y = Cost, color = Desc)) +
geom_line(data = samp2data, aes(x = Month, y = Total, color = "Total"))
# Adding +facet_wrap(~Desc) gives separate charts for each category
# and each also has the total plotted.
