R – lattice Packages
The lattice package uses grid package to provide better relationships between the data. It is an add-on package for the implementation of Trellis graphics (graphics that shows relationships between variables conditioned together).
To install Lattice Packages in R
install.packages("lattice")
There are so many graphs present in the package such as barchart, counterplot, densityplot, histogram, etc. A simple format to use is:
graph_type(formula, data)
where,
- graph_type represents the type of graph to represent
- formula specifies the variables or conditioned variables
To know about all functions of package:
library(help = "lattice")
Below is an implementation of some of the graphical functions in lattice package.
Example 1:
R
library (lattice) attach (mtcars) # Output to be present as PNG file png ( "DensityPlotLatticeGFG.png" ) # Create Density Plot for HP densityplot (~hp, main = "Density plot of HP" , xlab = "HP" ) # Saving the file dev.off () |
Output:
Example 2:
R
library (ToothGrowth) # Output to be present as PNG file png ( "HistogramLatticeGFG.png" ) # Using ToothGrowth dataset # To Create Histogram of length histogram (~len, data = ToothGrowth, main = "Histogram of Length" ) # Saving the file dev.off () |
Output:
Grid and Lattice Packages in R Programming
Every programming language has packages to implement different functions. Many functions are bundled together in a package. To use those functions, installation and loading of these packages are required. In R programming, there are 10, 000 packages in the CRAN repository. Grid and Lattice are some of the packages in R Programming Language which implement graphical functions to develop some graphical outputs such as rectangle, circle, histogram, barplot, etc.