Plot percentages on y-axis
library(scales)
dates <- 1:100
returns <- runif(100)
yticks_val <- pretty_breaks(n=5)(returns)
plot(dates, returns, yaxt="n")
axis(2, at=yticks_val, lab=percent(yticks_val))
Highlights:
- No need to explicitly add "%"
- Manually fix the number of y-ticks to be consistent with further plots. Here I chose 5.
Combining two answers together @rengis @vladiim
Here is one way using las=TRUE
to turn the labels on the y-axis and axis()
for the new y-axis with adjusted labels.
dates <- 1:10
returns <- runif(10)
plot(dates, returns, yaxt="n")
axis(2, at=pretty(returns), lab=pretty(returns) * 100, las=TRUE)
If you use ggplot you can use the scales package.
library(scales)
plot + scale_y_continuous(labels = percent)