let's say I have this simple df with its plot as follows :
df = data.frame(a = c('person1','person2','person3'),
b = c(10,20,30))
ggplot(df)+aes(x=a,y=b,fill=b)+
geom_bar(stat='identity')
the outcome
I wish that the legend is a box that only includes (for example) the following phrase : TOTAL = 60
Thanks a lot.

You could create an
annotationwith alabel. Make sure to create some space by changing theplot.marginandclipoff the coords. You can play with the settings. Here is a reproducible example:Created on 2022-12-12 with reprex v2.0.2
You could use
richtextwhen loadingggtextto rotate an annotated box like this:Created on 2022-12-12 with reprex v2.0.2