R : Basic Plots

06 May

R provide basic Plot command to draw line chart. syntax of plot command is :-

plot(x,y,  type, main, sub, xlab, ylab...)

Lets try to draw plot with various option

x=data.frame(wt = c(105, 120, 120, 160, 120, 145, 175, 160, 185, 210),
ht = c(61, 62, 63, 65, 65, 68, 69, 70, 72, 75))

# Partition R workspace in 3 * 3 matrix
par(mfrow=c(3, 3))
plot(x$ht, x$wt)
plot(x$ht, x$wt, type="p", main="type=p")
plot(x$ht, x$wt, type="l", main="type=l")
plot(x$ht, x$wt, type="b", main="type=b")
plot(x$ht, x$wt, type="c", main="type=c")
plot(x$ht, x$wt, type="o", main="type=o")
plot(x$ht, x$wt, type="h", main="type=h")
plot(x$ht, x$wt, type="s", main="type=s")
plot(x$ht, x$wt, type="S", main="type=S")


Lets try to beautify one of the plot. Apology for bad color choice. Just want to show the usage of color with different options.

par(bg="light grey")
plot(x$ht, x$wt, type="o", xlab="Height", ylab="Weight", main="Weight wrt Height", col="blue", pch=4, lty=4, col.axis="red", col.lab="brown", fg="dark blue", col.main="purple", font.axis=4, font.lab=4, font.main=4)




Line Symbols

We can draw lty with below line options


Plotting Symbols

We can use plot symbols (pch) with below options




We can use

4-Bold Italic

1 Comment

Posted by on May 6, 2015 in Basic Line Plot, R Basics


Tags: , , , ,

One response to “R : Basic Plots

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: