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

November 1, 2011
By

(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 

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , ,

Comments are closed.

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training

datasociety

http://www.eoda.de





ODSC

ODSC

CRC R books series





Six Sigma Online Training









Contact us if you wish to help support R-bloggers, and place your banner here.

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)