Search code examples
rggplot2pie-chart

Add percentage (%) for a PieChart


Hello guys i am trying to do a pie chart like the next picture: But i am getting a lot of problem

enter image description here

But this is the plot that I am getting:

ggpie(s, x="costes", label ="prop", lab.pos = "in", fill = "Implementation",
  lab.font = list(size= 5)) + scale_fill_manual(values = c("dodgerblue2","blue"))

How i could add percentage to my labels like 98.9%...etc

data: structure(list(Implementation = c("2", "1"), costes = c(6204670582.33, 70561379.07), prop = c(98.9, 1.1), lab.ypos = c(49.45, 99.45)), row.names = c(NA, -2L), class = c("tbl_df", "tbl", "data.frame"))

Thanks so much for your time


Solution

  • per <- c(0.1,0.2,0.3,0.4)
    labels <- c("a","b","c","d")
    pie(per,labels = paste0(labels," (",round(per,digits = 3)*100,"%)"),
        border="white",col = c("red","green","blue","yellow"))