Base Plot and Lattice Plot in R

Created on August 15 2015 At 8:26 PM

Back To The Main Blog Page


This Post I will try to cover up the basic forms of visualization in R which is Base and Lattice Plots. These plots are rather "primitive" especiall base plot and but are much for time-wise efficient as compared to other plots that I will post about. So lets get started.

Base Plot

Base Plot or R Base Graphic is the earliest form of ploting in R . It is very Lightweight and thus is more effcient in handling large databases very easily.
An important read to understand the documentation of the system at large would be this .

Scatter Plot

So one of the first things to look for in Base plotting System is the scatter plot . I have used cars dataset which is a preinstalled dataset which comes in R. Infact You can use many of the Rdatasets from here.

require(stats); require(graphics)
plot(cars, xlab = "Speed (mph)", ylab = "Stopping distance (ft)", las = 1)

Ok so one very clear this to notice here would be the linear regression followup of the data.To see it in the graph just type


which should produce something like this


The next plot that I will write about is Histogram . The code is ::

hist(dat,breaks = 10,xlim=range(dat),xlab="data",ylab="Frequency",col="blue",border = "red")

Here I have use rnorm to create an almost normal data sequence.

Lattice Plot

The documentation regarding Lattice Plot and its functions and arguments can be read about here . One of the major areas of improvization from Base plot was the idea to attach several plots in one single plot factored through some other aspect of the dataset . Altough this can be done using factoring by different color or other attribute in both Base as well as more advance plotting libraries but still sometimes this factorisation proves to be a core essence of the visualization in which case Lattice Plot is much more applicable . If you didn't follow the explanation well the the example might shed some light on the usage issue .
xyplot(mpg ~ hp | factor(cyl), data=mtcars)

Now this visulizaion might serve as a good enough model for understanding when to use lattice plot at large. The dataset which I have used is the "mtcars" dataset . Here while plotting between "mpg"(or miles per gallon) and "hp"(horsepower),the number of cylinders becomes an important factor to distinguish between different thresholds.Now you can allow different appropriate attributes to all the visualization like linear modulation .

xyplot(mpg ~ hp | factor(cyl), data=mtcars,type=c("p", "r"))

Now clearly doing this within Base Plot and other packages is much difficult but can be done in a breeze in Lattice Plot.

For any suggestion or comments feel free to contact me :: aaditya.jamuar [at]