You can use scales::comma
to handle this (and also easily make a reproducible example, even with a large amount of data):
library(ggplot2)
dat <- data.frame(
workers = c(
rep("Q8", 100000),
rep("A2", 200000),
rep("S1", 200000)
)
)
ggplot(dat, aes(x = factor(""), fill = workers) ) +
geom_bar() +
coord_polar(theta = "y") +
scale_x_discrete(name="") +
scale_y_continuous(label=scales::comma) +
theme_bw() +
theme(panel.grid=element_blank()) +
theme(panel.border=element_blank()) +
theme(axis.ticks=element_blank())
which produces this monstrosity:
![](https://i.stack.imgur.com/1scTA.png)
Note that you really should not display the "y" axis numbers since they make no sense in this context and should either direct label the pie slices or add the value #'s to the actual legend labels.
But, might I suggest turning to a different vis:
library(waffle)
library(dplyr)
count(dat, workers) %>%
mutate(trim=n/10000) -> df2
parts <- setNames(unlist(df2$trim), df2$workers)
waffle(parts, rows=4, title="Count", xlab="Each square represents 10,000 workers")
![enter image description here](https://i.stack.imgur.com/6Qagl.png)
If you're using the github version of ggplot2 you'll need to do:
waffle(parts, rows=4, title="Count", xlab="Each square represents 10,000 workers") +
scale_fill_manual(name="workers",
values=c(Q8="#e41a1c", A2="#377eb8", S1="#4daf4a"),
na.translate=FALSE)
as it has some different behaviour than the CRAN version (the waffle
pkg will be updated when the new ggplot2 is on CRAN).
scale_y_continuous
with somelabel
argument while specifying what formatting the variable count should take, possibly by a call toformat
. – shayaascipen
inoptions
. – shayaalibrary(scales)
? – Enrique