
ggplot2 needs at least the following three to produce a chart:
ggplot2ggplot2 include:
ggplot(): the main function to create a plotaes(): the function to specify the mapping of variables to axesgeom_*() or stat_*(): functions to add layers to the plotlabs(): the function to change labels of axes and titletheme(): the function to adjust non-data plot elements such as text size,In this lesson, we will focus on using different geometric objects and building the mapping.
geom’s) are used to represent the datapoints (aka observations)
For example: we can plot Age vs. Income using a scatterplot or a smoothed line
ggplot2 cheatsheet for a list of common geom_*() functionsCommon geom_*() for plots with one variable:
geom_histogram() (for numeric)geom_bar() (for categorical)geom_boxplot()geom_density()geom_dotplot()Common geom_*() for plots with two or more variables:
geom_point()geom_line()geom_boxplot()geom_smooth()geom_jitter()ggridges package is needed for the geom_density_ridges() function.
geom_density_ridges() to create a density plots of the age_yr variable (on the x-axis), grouped by the srh variable (on the y-axis). The density plots are stacked on top of each other to create a ridge plot.

aes() into ggplot() since both geom_boxplot() and geom_jitter() use the same mapping
alpha argument is used to make the points more transparent.

x = The x-axis variabley = The y-axis variableshape = Display a point with geom_point() as a dot, star, triangle, or square…fill = The interior color (e.g. of a bar or boxplot)color = The exterior line of a bar, boxplot, etc., or the point color if using geom_point()size = Size (e.g. line thickness, point size)alpha = Transparency (1 = opaque, 0 = invisible)binwidth = Width of histogram bins (for geom_histogram() only)width = Width of bar plot columns (for geom_bar() only)linetype = Line type (e.g. solid, dashed, dotted)
binwidth for geom_histogram())

Color is often NOT needed in a plot!!
Outside aes() (aesthetic setting)
darkgreen or 0.5For example:
Inside aes() (aesthetic mapping)
shape aesthetic inside aes()For example:
aes()
ggplot2
Data visualization: Basic plotting