0

I have the following codes running in R:

options(scipen=99)

sp <- ggplot(mydata2, aes(x=FY, y=PkgRev, fill=FY, label=PkgRev)) + geom_bar(stat = "identity") +  
geom_text(aes(label=PkgRev),size=3,position=position_dodge(width=0.9),vjust=-0.50)

sp

sp + facet_grid(Market ~ PropertyCode) +
theme(axis.title.x=element_blank(),
    axis.text.x=element_blank(),
    axis.ticks.x=element_blank(),
    axis.title.y=element_blank()) +
theme(legend.position="bottom") + 
theme(legend.title=element_blank()) +
 ggtitle('xxxxxxxx') +
 scale_y_continuous(breaks = seq(0, 170100000, by=50000000), limits=c(0,170100000))

The above codes give me the following output (extract shown):

image1

I want the y-axis tick values to be separated by a comma to represent thousands and the same principle on the text showing the values on top of the bars.

How do I achieve this?

user3115933
  • 4,303
  • 15
  • 54
  • 94

1 Answers1

1

You can use the scales package and add "labels = comma" to your scale_y_continuous() See this post for the axis Thousand separator in label of x or y axis And this for the geom_text including a comma separator for data labels in ggplot

so:

sp <- ggplot(mydata2, aes(x=FY, y=PkgRev, fill=FY, label=PkgRev)) + 
    geom_bar(stat = "identity") + 
    geom_text(aes(label=comma(PkgRev)),size=3,
         position=position_dodge(width=0.9),vjust=-0.50)

sp + facet_grid(Market ~ PropertyCode) +
    theme(axis.title.x=element_blank(),
    axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.title.y=element_blank()) +
    theme(legend.position="bottom") + 
    theme(legend.title=element_blank()) +
     ggtitle('xxxxxxxx') +
     scale_y_continuous(breaks = seq(0, 170100000, by=50000000), 
     limits=c(0,170100000), labels = comma)

should work

Sarah
  • 3,022
  • 1
  • 19
  • 40