label_percent returns a function, so it can be used like this:
ggplot(mydf, aes(x = cats, y = perc, label = label_percent()(perc))) +
geom_text()
However, that seems like a confusing syntax and I'm not sure if usage within a geom is an intended use case. Typically, I do something like this:
ggplot(mydf, aes(x = cats, y = perc)) +
geom_text(aes(label=sprintf("%1.1f%%", perc*100)))
To implement your own function, you could do:
pct = function(x, digits=1) {
sprintf(paste0("%1.", digits, "f%%"), x*100)
}
ggplot(mydf, aes(x = cats, y = perc)) +
geom_text(aes(label=pct(perc, 3)))