How to round a number in ggplot2 ?



Hello! I have a problem with my code, I need to round the number that are in my variable "ratio", here is the ggplot code

mydata <- (....source code)

ui <- (nothing special)

plotouput ("mydata")

server <- blablabla

output$mydata <- renderPlot ({

ggplot(mydata %>% filter(chart_name == 'AppDownloadUsage'), aes(x = chart_name, y = ratio, fill = slice_name)) +
geom_bar(colour="black",stat = "identity")+
geom_text(aes(label= ratio, position = "stack")

How can I round the number of my variable ratio?

Thank you very much for the help


I would round the variable in the data before plotting it using the round or signif functions (you can read more using ?round and ?signif)


I thought I would only work in ggplot but I needed to do it before, thank you very much, it works


You can round right in the aesthetic, if you want:


ggplot(data = mtcars, aes(x = mpg, y = round(wt, digits = 0))) +

Created on 2018-10-18 by the reprex package (v0.2.1.9000)