Reputation: 3851
I have a complex function of y in terms of x as below
y = 1-(e^(-((x^2)/730)))
or y equals 1-(e power minus (x-square/730))
How do i represent such complex functions in R? I want to draw a curve(graph) connecting all these points. I also want to mark x-axis from 0 to 370 with interval of 10. I know how to keep the breaks, but i don't know how i can label axes with numbers. If help is given somewhere, please guide me to that link. Much appreciated.
Upvotes: 0
Views: 396
Reputation: 226692
Check out the help for ?curve
, ?axis
...
## draw the curve
curve(1-exp(-x^2/730),from=0,to=370,axes=FALSE)
axis(side=2) ## add default lefthand axis
axis(side=1,at=seq(0,370,by=10)) ## add custom bottom axis
box(bty="l") ## add a box
One thing to note is that R suppresses overlapping labels, so unless you have a very wide plot you won't actually see every axis label. You can try adding cex.axis=0.5
(or even smaller) to your side-1 axis if you like. You could also check out the staxlab
function from the plotrix
package, or rotate the axis labels.
(You had a lot of superfluous parentheses in your expression; more parentheses don't really hurt, but in the long run you can make cleaner code (and spend less time counting parentheses) if you learn the order of operations.)
Upvotes: 4