# How can I plot this simple graph (Refer Image) in R?

I'm very new to R Programming. So please excuse for such a simple doubt. 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.

• the legend in your graph does not correspond to the graph of function $y=10^6/x$, is this intentional? Jan 25, 2011 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. Jan 25, 2011 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) Jan 25, 2011 at 15:02

I think all you need is:

 curve(1e6/x,0,2560)


Or perhaps:

plot(...<your data>...)

• This solution is a lot nicer than my "hackish" try! Jan 25, 2011 at 14:13
• +1, did not know about curve :) Always used plot directly. Jan 25, 2011 at 14:13
• For completeness, perhaps add text(2000, 30000, expression(paste("where xy=", 10^6)))? Jan 25, 2011 at 14:22
• @mpiktas: Good point ;) Jan 25, 2011 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) Jan 25, 2011 at 14:56

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))) • 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. Jan 25, 2011 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. Jan 25, 2011 at 14:58