Here you will find daily news and tutorials about R, contributed by over 750 bloggers.
There are many ways to follow us - By e-mail:On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here)

(This article was first published on CloudStat, and kindly contributed to R-bloggers)

Line Plots (Econometric in R)

Input:

## ---------------------------- ##
## Plotting Points *and* Lines ##
## ---------------------------- ##
pow = c(0.95, 0.6, 0.3, 0.15, 0.1, 0.05, 0.1, 0.15, 0.3, 0.6, 0.95)
pow2 = c(0.99, 0.75, 0.4, 0.2, 0.15, 0.05, 0.15, 0.2, 0.4, 0.75, 0.99)
thet = c(7:17)
plot(thet,pow) ## Plots points
plot(thet,pow2) ## Plots points on *new* plot
## But we want them on the same plot...
## Try options in plot
## Useful options in plot()
plot(thet,pow, type="l", col="red") ## Lines
plot(thet,pow, type="o", col="blue") ## Overplotted lines and points
plot(thet,pow, type="s", col="orange") ## Stair steps
## Less useful options
plot(thet,pow, type="b") ## "Both" lines and points
plot(thet,pow, type="c") ## "lines" part of "both"
plot(thet,pow, type="h", xlim=c(0, 20),ylim=c(0,1)) ## Histogram-like
plot(thet,pow, type="n",xlim=c(0, 20),ylim=c(0,1)) ## No plotting... ?
## Note: xlim = c(low,high) sets low to be the lower limit for the x-axis and high to be the upper limit.
## ylim = c(low,high) does the same for the y-axis. These can be useful for
## Points and Lines to put on top of the active plot
plot(thet,pow, type="n",xlim=c(0, 20),ylim=c(0,1)) ## No plotting... ?
points(thet,pow2, col="blue")
lines(thet,pow2, col="green")
lines(thet,pow, col="red", type="o") ## plot() options work for lines() and points()
title("My CloudStat Plot") ## Sometimes it is nice to add a title

Related

To leave a comment for the author, please follow the link and comment on their blog: CloudStat.