LAbeling with Percentage in R plot

Posted by Libo Cannici on Stack Overflow See other posts from Stack Overflow or by Libo Cannici
Published on 2010-06-18T14:59:55Z Indexed on 2010/06/18 15:03 UTC
Read the original article Hit count: 182

Filed under:

Hi I have made this function that takes a table and prepare the label for a barplot

prepare_labels <- function(ft){
  labs <- ft
  labs <- paste(labs, "\n", sep="")
  labs <- paste(labs, round(prop.table(ft)*100,2), sep="")
  labs <- paste(labs, "%", sep="")
  return(labs)
}

It actually works fine, but is there any better way to write that function, the above code looks ugly and I want to write beautiful code :-)

ex:

ft <- table(mydata$phone_partner_products)
prepare_labels(ft)
[1] "3752\n34.09%" "226\n2.05%"   "2907\n26.41%" "1404\n12.76%" "1653\n15.02%"
[6] "1065\n9.68%" 

© Stack Overflow or respective owner

Related posts about r