0

I've been asked by my boss to replace the "0"'s above my bar labels with "n/a" for publication purposes.

The code I ran:

geom_text(aes(label = round(variable, digits = 0), , vjust = -0.5, colour = "black")

What I get:

enter image description here

benson23
  • 16,369
  • 9
  • 19
  • 38
  • We don't quite have enough to provide exact feedback, but if you create a new dataframe for your `geom_text()` layer and replace the 0's with NA and make the call to labels: `geom_text(data=labeldata,aes(x=x,y=columnvalue,labels=labelcolumn)` – dandrews Mar 16 '23 at 21:02
  • Hi, please provide a reproducible example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – william3031 Mar 16 '23 at 22:23

1 Answers1

0

Here's an example using built in data:

library(tidyverse)
labeldata=data.frame(cut=c('Fair','Good','Very Good','Premium','Ideal'),
                     table=c(NA,300000,750000,900000,1250000),
                     label=as.character(c(0,300000,750000,900000,1250000))) %>% 
  mutate(table=ifelse(is.na(table),0,table))
labeldata
ggplot(data = diamonds) +
  geom_col(aes(x=cut,y=table)) +
  geom_text(data = labeldata,
            aes(x=cut,y=table,label=label))
dandrews
  • 967
  • 5
  • 18