Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I'm very new to R Programming. So please excuse for such a simple doubt. How to plots this graph in R?

I want to plot the above graph. The x & y values are sequence from 0 to 2560. I want plot a a curve on the points where x*y=10^6.

What are the line required in R Programming Language.

share|improve this question
the legend in your graph does not correspond to the graph of function $y=10^6/x$, is this intentional? – mpiktas Jan 25 '11 at 14:15
Thanks @mpiktas. My mistake. And my intention is not y=10^6/x. I want to make a graph with x & y values and the mark the points(curve) where the values of x & y satisfies (x*y=10^6). Is it possible? Not sure if this is mathematical correct or not. – Saneef Jan 25 '11 at 14:54
For reference: en.wikipedia.org/wiki/File:Vector_Video_Standards2.svg I want to plot the line which acts as the boundary for yellow on the lower right (>1M pixels) – Saneef Jan 25 '11 at 15:02

2 Answers

I think all you need is:

 curve(1e6/x,0,2560)

EDIT in light of comments:
Or perhaps:

plot(...<your data>...)
curve(1e6/x, 1e6/2560,2560, add=TRUE)
share|improve this answer
This solution is a lot nicer than my "hackish" try! – daroczig Jan 25 '11 at 14:13
+1, did not know about curve :) Always used plot directly. – mpiktas Jan 25 '11 at 14:13
For completeness, perhaps add text(2000, 30000, expression(paste("where xy=", 10^6)))? – csgillespie Jan 25 '11 at 14:22
@mpiktas: Good point ;) – csgillespie Jan 25 '11 at 14:38
But I want to make graph with x & y values and the mark the points(curve) where the values of x & y satisfies (x*y=10^6) – Saneef Jan 25 '11 at 14:56
show 2 more comments

The easiest way is to compute all y values at every given x values, like:

df <- data.frame(x=1:2560)
df$y <- 10^6/df$x
# the latter equivalent to:
# df <- within(df,y<-10^6/x)

And after plot the dataframe:

plot(df, type="l", main=expression(f(x) == frac(10^{6},x)))

enter image description here

share|improve this answer
1  
why use loop? df <- within(df,y<-10^6/x) is much nicer and more efficient. Also OP asks for line, so you need to supply type="l" in your plot function. – mpiktas Jan 25 '11 at 14:17
@mpiktas: true! It is terrible, that I fall into a habbit always using loops :( I edit my answer based on your suggestions. – daroczig Jan 25 '11 at 14:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.