Skip to main content

Menu

LEVEL 0
0/5 XP
HomeAboutTopicsPricingMy VaultStatsPractice TestsCertifications

Categories

🎓 Certifications
🤖 Artificial Intelligence
☁️ Cloud and Infrastructure
💾 Data and Databases
💼 Professional Skills
🎯 Programming and Development
🔒 Security and Networking
📚 Specialized Topics
CheatGrid
HomeAboutTopicsPricingMy VaultStatsPractice TestsCertifications
LVLEVEL 0
0/5 XP
GitHub
© 2026 CheatGrid™. All rights reserved.
Privacy PolicyTerms of UseAboutContact

ggplot2 Cheat Sheet

ggplot2 Cheat Sheet

Back to Data Science
Updated 2026-04-27
Next Topic: Gradio ML Demo and App Framework Cheat Sheet

ggplot2 is R's most powerful data visualization package, built on the Grammar of Graphics—a systematic framework that treats plots as compositions of independent layers (data, aesthetics, geometries, statistics, scales, coordinates, and facets). Originally created by Hadley Wickham, ggplot2 is now the industry standard for publication-quality graphics in R, deeply integrated into the tidyverse ecosystem. Unlike base R plotting, which describes what to draw, ggplot2 describes how variables map to visual properties, enabling you to build complex visualizations incrementally. The key mental model: every plot is a layered combination of components added with +, where swapping one layer (e.g., geom_point() for geom_line()) transforms the visualization without rewriting the entire plot. As of version 4.0.0 (2025), ggplot2 uses an S7 backend and introduces element_geom() for controlling geom appearance through the theme system.


What This Cheat Sheet Covers

This topic spans 21 focused tables and 202 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.

Table 1: Core Building BlocksTable 2: Geoms for Points and LinesTable 3: Geoms for Distributions and UncertaintyTable 4: Geoms for Categorical, Bar, and Grid DataTable 5: Geoms for Text and AnnotationsTable 6: Geoms for Spatial DataTable 7: Statistical TransformationsTable 8: Position AdjustmentsTable 9: Coordinate SystemsTable 10: Faceting for Small MultiplesTable 11: Scale Functions for AxesTable 12: Color and Fill ScalesTable 13: Other Aesthetic ScalesTable 14: Built-in ThemesTable 15: Theme Elements for CustomizationTable 16: Common Theme ArgumentsTable 17: Legends and GuidesTable 18: Advanced TechniquesTable 19: Plot Composition and ArrangementTable 20: Saving and ExportTable 21: Extension Packages

Table 1: Core Building Blocks

These are the seven layers (plus saving) that every ggplot2 plot is assembled from. Start with ggplot() and aes() to declare your data and mappings, then keep adding geoms, scales, coordinates, facets, and themes with + until the picture is right — understanding how these pieces fit together is the whole game.

ComponentExampleDescription
ggplot()
ggplot(data = df, aes(x, y))
• Initializes a plot object
• specifies data and global aesthetic mappings inherited by all layers.
aes()
aes(x = mpg, y = hp, color = cyl)
• Maps variables to aesthetics (x, y, color, fill, size, shape, alpha, linetype)
• placed in ggplot() for global or in geom_*() for layer-specific.
geom_*()
geom_point()
geom_line()
• Defines the geometric object (visual representation)
• each geom creates a new layer.
stat_*()
stat_summary(fun = mean)
• Applies statistical transformation before plotting
• every geom has a default stat (e.g., geom_bar() uses stat_count()).
scale_*()
scale_x_continuous()
scale_color_manual()
• Controls how data values map to visual properties
• customizes axes, colors, sizes, limits, labels, and transformations.

More in Data Science

  • GeoPandas Cheat Sheet
  • Gradio ML Demo and App Framework Cheat Sheet
  • AB Testing and Online Experimentation Cheat Sheet
  • Design of Experiments (DOE) Cheat Sheet
  • OpenRefine Cheat Sheet
  • SciPy Cheat Sheet
View all 47 topics in Data Science