Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot percentages on y-axis

Tags:

plot

r

I'm plotting a graph using this

plot(dates,returns)

I would like to have the returns expressed as percentages instead of numbers. 0.1 would become 10%. Also, the numbers on the y-axis appear tilted 90 degrees on the left. Is it possible to make them appear horizontally?

like image 567
Youcha Avatar asked Jul 26 '12 17:07

Youcha


People also ask

How do I get Y axis percentage in MatPlotLib?

MatPlotLib with PythonCreate a list of numbers as y. Create a number of bins. Plot a histogram using hist() method, where y, bins, and edgecolor are passed in the argument. Store the patches to set the percentage on Y-axis.


1 Answers

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)
like image 75
johannes Avatar answered Oct 25 '22 20:10

johannes