Label ggplot2 plot

I am looking for a way to write the labels of my plot, which has been flipped using coord_flip(), next to bars of the plot. Reproducible example:

Names <- c("ExampleA","ExampleB","ExampleC","ExampleD", "ExampleE", "ExampleF","ExampleG", "ExampleH")
Counts <- c(4,3,2,1,-1,-2,-3,-4)
Type <- c("X","X","X","X", "Y","Y","Y","Y")
df <-data.frame(Names,Counts, Type)

ggplot(df, aes(x=reorder(Names,Counts), y=Counts, fill=Type))+
  geom_col()+
  coord_flip()+
  theme_minimal()

I need to write the labels of the plot (Names) next to the bars. I’ve tried geom_label with parse=TRUE and scale_x_discrete with position="inside", but neither has worked.

Do you know of any other way to achieve my goal?

You can achieve your goal by using the geom_text() function to add the labels next to the bars. Here’s the modified code:

ggplot(df, aes(x=reorder(Names,Counts), y=Counts, fill=Type))+
  geom_col()+
  coord_flip()+
  geom_text(aes(label=Names), hjust=0, vjust=0.5, color="white")+
  theme_minimal()

This code adds the geom_text() layer to the plot, specifying the label aesthetic as Names to display the names next to the bars. The hjust=0 argument aligns the labels to the left of the bars, and vjust=0.5 centers the labels vertically. The color="white" argument sets the label color to white for better visibility against the bars.