Possible Duplicate:
How to format a number as percentage in R?
This must be a newbie questions, but how do I format numbers in charts (say PerformanceSummary in PerformanceAnalytics) as percentages? The data I use are in the format of 0.04 etc. Everything is working fine, except I want the charts to show percentages.
Thanks in advance
EDIT:
Here is how I am doing it now (with standard data for simplicity reasons):
library("PerformanceAnalytics")
data(managers)
charts.PerformanceSummary(managers)
I put it here while I go googling for providing my own labels.
Select the decimal number cells, and then click Home > % to change the decimal numbers to percentage format. 7. Then go to the stacked column, and select the label you want to show as percentage, then type = in the formula bar and select percentage cell, and press Enter key.
Unless I miss something, I don't think this is a newbie question at all.
(Disclaimer: I think this answer isn't particularly elegant, and the graphic sucks. But hopefully it can serve as a template so somebody else can improve and post some proper code.)
Here is one way of doing it in base graphics:
yaxt="n"
seq
sprintf
and round
to format the labels as text with percentage signSome code:
set.seed(1)
x <- runif(10)
plot(x, type="h", yaxt="n")
yLabels <- seq(0.2, 0.8, 0.2)
axis(2, at=yLabels, labels=sprintf(round(100*yLabels), fmt="%2.2f%%"), las=1)
The plot:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With