Line Plots (Econometric in R) Input: ##…

[This article was first published on CloudStat, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.



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 

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

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)