After running the following code, I receive the error:
Error in comma(count) : could not find function "comma"
ggplot(mydata, aes(xvar, fill=yvar)) +
geom_bar(alpha = 0.7) +
scale_y_continuous(breaks = seq(0, 14000, by=1000), label = comma) +
labs(title="title", x="xlab", y="ylab") +
scale_fill_manual(values=c("gold2", "forestgreen", "dimgrey")) +
theme(panel.background = element_rect(fill = 'gray95'),
title = element_text(face = "bold.italic", color = "black"),
plot.title = element_text(hjust = 0.5)) +
geom_text(stat = "count",
aes(label = comma(..count..)),
size = 4,
position = position_stack(vjust = 0.50))
Once I remove the comma()
function from within geom_text()
, the code runs fine and produces the graph I want, except the data labels are not in comma format. I have the 'scales' package loaded and even use label = comma
in the scale_y_continuous()
line. What am I doing wrong here?