Adding Currency Dollar Sign $ to each bar in a bar graph

I am trying to add a $ currency symbol to each number listed on my bar graph.

The numbers are displaying correctly at the top of the bars. How do I add a $ before each number?

I read the CSV file into R and they are unlabeled numbers. I used this code to get a $ on the Y axis, successfully:

'''scale_y_continuous(labels=scales::dollar_format())'''

I used this next code below to get the NUMBER on top of each bar. Where would I made an amendment to get the $ on the bar? Is it a new line of code or within the geom_text line below? Appreciate any help here, I am a rookie!

'''geom_text(aes(label = CareerEarnings), vjust = 1.5, colour = "white")+'''

For visual...these are my bars which are missing the dollar signs, I got the dollar signs on the far left for the Y axis and that's pictured here:

Hello,

You can use dollar from the scales library (which seems you are using) to directly add dollar signs and specify digits to the label.

libary(scales)
geom_text (aes(label = scales::dollar(CareerEarnings,digits = 0)), color = "black")

It's a pretty useful library! dollar_format() would also work instead of dollar(), but I'm not sure if you would have to lose the digits part of the syntax.

1 Like

bingo! thanks so much! I added the vjust section in there so it fit correctly piggybacking off the code you had sent along. I also set it to white text for my bar graph

geom_text (aes(label = scales::dollar(CareerEarnings,digits = 3)),vjust = 1.5, color = "white")

in this ggplot scenario...do you have any code to add a text bubble/image onto the background of the plot?

where I could add something catchy, in the background with a small powerful sentence.

I unfortunately don't, but interestingly enough I was looking into this topic earlier today for something else. Check out section 8.3 from this ggplot2 book: ggplot2: Elegant Graphics for Data Analysis (3e) - 8  Annotations

For example, this will create the text for you (caption is the string of the text you want to include):

There's also lots of good stuff in there about ggplot2 topics I refer to from time to time.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.