ggplot2 is a popular data visualization package in R that allows users to create stunning and informative graphics. Developed by Hadley Wickham, ggplot2 is based on the grammar of graphics, which provides a systematic way of mapping data to visual elements such as points, lines, and bars.
Basic Elements
Element Description ggplot()
Initializes a plot aes()
Defines aesthetic mappings geom_*()
Adds geometric objects to the plot scale_*()
Modifies the scale of an aesthetic labs()
Adds labels to the plot theme()
Modifies the appearance of the plot
Geometric Objects
Object Description geom_point()
Adds points to the plot geom_line()
Adds lines to the plot geom_path()
Adds a path connecting points geom_bar()
Adds bars to the plot geom_histogram()
Adds a histogram to the plot geom_density()
Adds a density plot to the plot geom_boxplot()
Adds a boxplot to the plot geom_violin()
Adds a violin plot to the plot geom_smooth()
Adds a smoothed line to the plot
Aesthetic Mappings
Mapping Description x
X-axis variable y
Y-axis variable color
Color of the object fill
Fill color of the object size
Size of the object shape
Shape of the object linetype
Line type of the object alpha
Transparency of the object
Scales
Scale Description scale_x_continuous()
Modifies the X-axis scale scale_y_continuous()
Modifies the Y-axis scale scale_color_*()
Modifies the color scale scale_fill_*()
Modifies the fill color scale scale_size_*()
Modifies the size scale scale_shape_*()
Modifies the shape scale scale_linetype_*()
Modifies the line type scale scale_alpha_*()
Modifies the transparency scale
Labels
Label Description xlab()
X-axis label ylab()
Y-axis label ggtitle()
Plot title labs()
Adds multiple labels
Themes
Theme Elements
Element Description axis.title
Axis title axis.text
Axis text axis.line
Axis line axis.ticks
Axis ticks panel.background
Panel background panel.border
Panel border panel.grid
Panel grid plot.background
Plot background plot.title
Plot title legend.background
Legend background legend.title
Legend title legend.text
Legend text
Theme Functions
Function Description theme_bw()
Black and white theme theme_classic()
Classic theme theme_dark()
Dark theme theme_light()
Light theme theme_minimal()
Minimal theme theme_void()
No theme
Reference
ggplot2 documentation: https://ggplot2.tidyverse.org/