0

I have created a combined chart (Barchart and line) with ggplot. Now, I want to show the total amount above the line and bar. Unfortunately, I can only find explanations on how to add a label to a non-combined chart.

My code for the chart is the following:

ggplot(Ann_Distribution)+
  geom_bar(aes(x=Year,y=TOTAL),stat='sum')+
  geom_line(aes(x=Year,y=EO), color="Black", group = 1, size = 1) +
  xlab("Year") +
  ylab("Amount") + 
  geom_label(aes(label = TOTAL), position = position_stack(vjust = 0.75)) +
  geom_label(aes(label = EO))
Peet
  • 1
  • Hello Peet and welcome to SO! Please share a dput() of your data (https://stackoverflow.com/questions/49994249/example-of-using-dput) so others can reproduce the code. – Santiago Capobianco Dec 25 '22 at 16:03

1 Answers1

0

It's always good to include a reproducible data set to make it easier for people to help you. I've used mtcars here as an an example. You can add different x,y for multiple labels to mirror your bar (here I used col) and lines.

ggplot(mtcars[1:5,]) +
    geom_col(aes(x = wt, y = mpg)) +
    geom_line(aes(x = wt, y = qsec)) +
    geom_label(aes(x = wt, y = mpg, label = mpg)) +
    geom_label(aes(x = wt, y = qsec, label = qsec))

enter image description here

stomper
  • 1,252
  • 1
  • 7
  • 12