[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-572746-105":3,"detail-sidebar-cat-1-en-105":85,"doc-detail-572746-en":130},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":78,"head_meta":80,"extra_data":82,"updated_unix":84},105,"en","data-visualization-with-ggplot2-cheat-sheet","Data Visualization with ggplot2 - Cheat Sheet","","A compact ggplot2 cheat sheet explaining how to build graphics using the grammar of graphics: data sets, geoms, and coordinate systems. Covers mapping data variables to aesthetics, constructing plots with qplot() and ggplot(), and adding layers using geom_*() and stat_*() functions. Includes guidance and example geoms for one and two variables, graphical primitives, bivariate distributions, functions, error visualization, map geoms, and three-variable spatial plots. Also describes saving plots with ggsave().",{"@graph":14,"@context":77},[15,34,56],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/template/","Template",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/template/presentations/","Presentations",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/template/data-visualization-with-ggplot2-cheat-sheet/572746/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/data-visualization-with-ggplot2-cheat-sheet/572746.png","ImageObject",442,249,{"name":42,"@type":43},"Chumphorn","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-10-21","2026-10-13",true,{"@type":52,"interactionType":53,"userInteractionCount":55},"InteractionCounter",{"@type":54},"ViewAction",5,{"@type":57,"mainEntity":58},"FAQPage",[59,65,69,73],{"name":60,"@type":61,"acceptedAnswer":62},"How does ggplot2 define the components of a plot?","Question",{"text":63,"@type":64},"ggplot2 follows the grammar of graphics, combining a data set, one or more geoms (visual marks), and a coordinate system. Variables are mapped to aesthetic properties such as x/y positions, color, size, and other styling attributes.","Answer",{"name":66,"@type":61,"acceptedAnswer":67},"What is the difference between qplot() and ggplot()?",{"text":68,"@type":64},"qplot() creates a complete plot with given data, geom, and mappings, using many useful defaults. ggplot() starts a plot that you finish by adding layers with +, providing more control and fewer defaults.",{"name":70,"@type":61,"acceptedAnswer":71},"How do you add layers to a ggplot?",{"text":72,"@type":64},"Use the + operator to add new elements. Each layer is created with a geom_*() or stat_*() call, which supplies its geom, aesthetic mappings, default stat, and any position adjustments.",{"name":74,"@type":61,"acceptedAnswer":75},"Which geoms are commonly used for different data patterns?",{"text":76,"@type":64},"The cheat sheet groups geoms by use case: density, histogram, and dot plots for one-variable distributions; points, jitter, boxplots, and violins for two-variable relationships; bin2d/hex for bivariate distributions; and errorbar/crossbar geoms for error visualization. It also includes map geoms for geographic plotting and contour/raster/tile for three-variable spatial data.","https://schema.org",{"og:url":32,"og:type":79,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":81,"canonical":32},"index,follow",{"doc_id":83,"site_id":7},572746,1792338197,{"code":4,"msg":86,"data":87},"success",[88,92,97,102,107,112,117,122,126],{"id":89,"doc_module":22,"doc_module_name":25,"category_name":29,"show_sort_weight":90,"slug":91},11,90,"presentations",{"id":93,"doc_module":22,"doc_module_name":25,"category_name":94,"show_sort_weight":95,"slug":96},12,"Resumes",80,"resumes",{"id":98,"doc_module":22,"doc_module_name":25,"category_name":99,"show_sort_weight":100,"slug":101},14,"Invoices",70,"invoices",{"id":103,"doc_module":22,"doc_module_name":25,"category_name":104,"show_sort_weight":105,"slug":106},15,"Posters",60,"posters",{"id":108,"doc_module":22,"doc_module_name":25,"category_name":109,"show_sort_weight":110,"slug":111},16,"Social Media",50,"social-media",{"id":113,"doc_module":22,"doc_module_name":25,"category_name":114,"show_sort_weight":115,"slug":116},17,"Forms",40,"forms",{"id":118,"doc_module":22,"doc_module_name":25,"category_name":119,"show_sort_weight":120,"slug":121},18,"Letters",30,"letters",{"id":123,"doc_module":22,"doc_module_name":25,"category_name":124,"show_sort_weight":55,"slug":125},21,"Paper Templates","papers-templates",{"id":127,"doc_module":22,"doc_module_name":25,"category_name":128,"show_sort_weight":4,"slug":129},158,"General","general-158",{"code":4,"msg":86,"data":131},{"doc_id":83,"user_id":132,"nickname":42,"user_avatar":133,"doc_module":22,"category_id":89,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":55,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":26,"language":139,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":140,"faqs":141,"seo_title":142,"seo_description":12,"update_tm":143,"read_time":22},2336475401981,"https://ap-avatar.wpscdn.com/avatar/22000c94efd8d5204d?x-image-process=image/resize,m_fixed,w_180,h_180&k=1786935347598174694","Data Visualization  \nwith ggplot2  \nCheat Sheet  \nBasics  \nggplot2 is based on the grammar of graphics, the idea that you can build every graph from the same few components: a data set, a set of geoms—visual marks that represent data points, and a coordinate  \nsystem.  \n+  \ndata geom  \nx = F  \ny = A  \ncoordinate plot system  \nTo display data values, map variables in the data set to aesthetic properties of the geom like size, color, and x and y locations.  \n+  \n\n| F | M | A |\n| --- | --- | --- |\n|  |  |  |\n|  |  |  |\n|  |  |  |\n|  |  |  |\n|  |  |  |\n|  |  |  |\n\ndata geom  \nx = F  \ny = A color = F size = A  \n4  \n3  \n= 2  \n1  \n0  \n0 1 2 3 4  \ncoordinate plot system  \nBuild a graph with qplot() or ggplot()  \n aesthetic mappings   data   geom   \nqplot(x = cty, y = hwy, color = cyl, data = mpg, geom = \"point\") Creates a complete plot with given data, geom, and mappings. Supplies many useful defaults.  \nggplot(data = mpg, aes(x = cty, y = hwy))  \nBegins a plot that you finish by adding layers to. No defaults, but provides more control than qplot() .  \nadd layers,  \nelements with +  \nlayer = geom + default stat + layer specific mappings  \nadditional elements  \nAdd a new layer to a plot with a geom_ *() or stat_ *() function. Each provides a geom, a set of aesthetic mappings, and a default stat and position adjustment.  \nlast_plot()  \nReturns the last plot  \nggsave(\"plot.png\", width = 5, height = 5)  \nSaves last plot as 5’ x 5’ file named \"plot. png\" in working directory. Matches file type to file extension.  \nGeoms -Use a geom to represent data points, use the geom’s aesthetic properties to represent variables. Each function returns a layer.  \nOne Variable  \nContinuous  \na \u003C-ggplot(mpg, aes(hwy))  \na + geom_area(stat = \"bin\")  \nx, y, alpha, color, fill, linetype, size  \nb + geom_area(aes(y = ..density..), stat = \"bin\")  \na + geom_density(kernel = \"gaussian\") x, y, alpha, color, fill, linetype, size, weight b + geom_density(aes(y = ..county..))  \na + geom_dotplot()  \nx, y, alpha, color, fill  \na + geom_freqpoly()  \nx, y, alpha, color, linetype, size  \nb + geom_freqpoly(aes(y = ..density..))  \na + geom_histogram(binwidth = 5) x, y, alpha, color, fill, linetype, size, weight b + geom_histogram(aes(y = ..density..))  \nDiscrete  \nb \u003C-ggplot(mpg, aes(fl))  \nb + geom_bar()  \nx, alpha, color, fill, linetype, size, weight  \nGraphical Primitives  \nc \u003C-ggplot(map, aes(long, lat))  \nc + geom_polygon(aes(group = group)) x, y, alpha, color, fill, linetype, size  \nd \u003C-ggplot(economics, aes(date, unemploy))  \nd + geom_path(lineend=\"butt\", linejoin=\"round’, linemitre=1)  \nx, y, alpha, color, linetype, size  \nd + geom_ribbon(aes(ymin=unemploy-900, ymax=unemploy + 900))  \nx, ymax, ymin, alpha, color, fill, linetype, size  \ne \u003C-ggplot(seals, aes(x = long, y = lat))  \ne + geom_segment(aes( xend = long + delta_long, yend = lat + delta_lat))  \nx, xend, y, yend, alpha, color, linetype, size e + geom_rect(aes(xmin = long, ymin = lat,  \nxmax= long + delta_long, ymax = lat + delta_lat))  \nxmax, xmin, ymax, ymin, alpha, color, fill, linetype, size  \nTwo Variables  \nContinuous X, Continuous Y  \nf \u003C-ggplot(mpg, aes(cty, hwy))  \nf + geom_blank()  \nf + geom_jitter()  \nx, y, alpha, color, fill, shape, size  \nf + geom_point()  \nx, y, alpha, color, fill, shape, size  \nf + geom_quantile()  \nx, y, alpha, color, linetype, size, weight  \nf + geom_rug(sides = \"bl\") alpha, color, linetype, size  \nf + geom_smooth(model = lm)  \nx, y, alpha, color, fill, linetype, size, weight  \nCAB  \nf + geom_text(aes(label = cty))  \nx, y, label, alpha, angle, color, family, fontface, hjust, lineheight, size, vjust  \nDiscrete X, Continuous Y  \ng \u003C-ggplot(mpg, aes(class, hwy))  \ng + geom_bar(stat = \"identity\")  \nx, y, alpha, color, fill, linetype, size, weight  \ng + geom_boxplot()  \nlower, middle, upper, x, ymax, ymin, alpha, color, fill, linetype, shape, size, weight  \ng + geom_dotplot(binaxis = \"y\", stackdir = \"center\")  \nx, y, alpha, color, fill  \ng + geom_violin(scale = \"area\")  \nx, y, alph","cbCaigjdIpugm5h6","https://ap.wps.com/l/cbCaigjdIpugm5h6","pdf",1231368,"English","# Basics\n## Grammar of graphics\n## Build a graph with qplot() or ggplot()\n# Layers and geoms\n## Adding layers with +\n## Geoms and aesthetics\n# Geom categories\n## One variable (continuous, discrete)\n## Graphical primitives\n## Two variables\n## Continuous bivariate distribution\n## Continuous function\n## Visualizing error\n## Maps\n## Three variables","[{\"question\":\"How does ggplot2 define the components of a plot?\",\"answer\":\"ggplot2 follows the grammar of graphics, combining a data set, one or more geoms (visual marks), and a coordinate system. Variables are mapped to aesthetic properties such as x/y positions, color, size, and other styling attributes.\"},{\"question\":\"What is the difference between qplot() and ggplot()?\",\"answer\":\"qplot() creates a complete plot with given data, geom, and mappings, using many useful defaults. ggplot() starts a plot that you finish by adding layers with +, providing more control and fewer defaults.\"},{\"question\":\"How do you add layers to a ggplot?\",\"answer\":\"Use the + operator to add new elements. Each layer is created with a geom_*() or stat_*() call, which supplies its geom, aesthetic mappings, default stat, and any position adjustments.\"},{\"question\":\"Which geoms are commonly used for different data patterns?\",\"answer\":\"The cheat sheet groups geoms by use case: density, histogram, and dot plots for one-variable distributions; points, jitter, boxplots, and violins for two-variable relationships; bin2d/hex for bivariate distributions; and errorbar/crossbar geoms for error visualization. It also includes map geoms for geographic plotting and contour/raster/tile for three-variable spatial data.\"}]","Data Visualization with ggplot2 - Cheat Sheet | PDF",1791929112]