Page 251 - Data Science class 11
P. 251
This will cause the "Install Packages" window to open. Fill ggplot2 in the Packages option as shown below:
After filling the Package option, press Install. This will cause the ggplot2 package to be installed.
A few of the essential functions under the ggplot2 package include the ggplot function & the geom functions. ggplot
graphics are built gradually by adding new elements. This approach makes plotting flexible and customizable. To
build a ggplot, the basic template used for generating different types of plot is: ggplot(data =, mapping = aes()) + ().
Using the ggplot function, you bind the plot to a data frame. This is done using the data argument.
You can define an aesthetic mapping (using the aesthetic (aes) function) by selecting the variables to be plotted and
specifying how to present them in the graph, e.g. as x/y positions or characteristics such as size, shape, colour, etc.
GEOM_FUNCTION represents the graphical representation of the data in the plot in the form of points, lines, or bars.
The most common forms of geom functions are:
• geom_point() [ used for scatter plots, dot plots, etc.]
• geom_boxplot() [used for boxplots]
• geom_line() [used for trend lines, time series, etc.
To add a geom function to the ggplot function, we use a ‘+’ operator.
Coding for Data Science Visualisation using R-Studio 249

