{"id":8312,"date":"2018-12-30T14:11:15","date_gmt":"2018-12-30T12:11:15","guid":{"rendered":"https:\/\/www.datanovia.com\/en\/?post_type=dt_lessons&#038;p=8312"},"modified":"2019-11-17T20:30:35","modified_gmt":"2019-11-17T18:30:35","slug":"introduction-to-ggplot2","status":"publish","type":"dt_lessons","link":"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/","title":{"rendered":"Introduction to GGPlot2"},"content":{"rendered":"<div id=\"rdoc\">\n<div id=\"what-is-ggplot2\" class=\"section level2\">\n<h2>What is ggplot2<\/h2>\n<p><strong>GGPlot2<\/strong> is a powerful and a flexible R package, implemented by Hadley Wickham, for producing elegant graphics piece by piece <span class=\"citation\">(Wickham et al. 2017)<\/span>.<\/p>\n<p>The <strong>gg<\/strong> in ggplot2 means <em>Grammar of Graphics<\/em>, a graphic concept which describes plots by using a \u201cgrammar\u201d. According to the ggplot2 concept, a plot can be divided into different fundamental parts: <strong>Plot = data + Aesthetics + Geometry<\/strong><\/p>\n<ul>\n<li><strong>data<\/strong>: a data frame<\/li>\n<li><strong>aesthetics<\/strong>: used to indicate the <strong>x<\/strong> and <strong>y<\/strong> variables. It can be also used to control the <strong>color<\/strong>, the <strong>size<\/strong> and the <strong>shape<\/strong> of points, etc\u2026..<\/li>\n<li><strong>geometry<\/strong>: corresponds to the type of graphics (histogram, box plot, line plot, \u2026.)<\/li>\n<\/ul>\n<div class=\"warning\">\n<p>The ggplot2 syntax might seem opaque for beginners, but once you understand the basics, you can create and customize any kind of plots you want.<\/p>\n<p>Note that, to reduce this opacity, we recently created an R package, named <strong>ggpubr<\/strong> (ggplot2 Based Publication Ready Plots), for making ggplot simpler for students and researchers with non-advanced programming backgrounds.<\/p>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Contents:<\/p>\n<div id=\"TOC\">\n<ul>\n<li><a href=\"#what-is-ggplot2\">What is ggplot2<\/a><\/li>\n<li><a href=\"#key-functions\">Key functions<\/a><\/li>\n<li><a href=\"#example-of-plots\">Example of plots<\/a><\/li>\n<li><a href=\"#legend-position\">Legend position<\/a><\/li>\n<li><a href=\"#titles-and-axis-labels\">Titles and axis labels<\/a><\/li>\n<li><a href=\"#facet-plot-with-multiple-pnels\">Facet: Plot with multiple pnels<\/a><\/li>\n<li><a href=\"#ggplot-theme\">GGPlot theme<\/a><\/li>\n<li><a href=\"#further-customizations-of-a-ggplot\">Further customizations of a ggplot<\/a><\/li>\n<li><a href=\"#save-ggplots\">Save ggplots<\/a><\/li>\n<li><a href=\"#conclusion\">Conclusion<\/a><\/li>\n<li><a href=\"#references\">References<\/a><\/li>\n<\/ul>\n<\/div>\n<div class='dt-sc-hr-invisible-medium  '><\/div>\n<div class='dt-sc-ico-content type1'><div class='custom-icon' ><a href='https:\/\/www.datanovia.com\/en\/product\/ggplot2-essentials-for-great-data-visualization-in-r\/' target='_blank'><span class='fa fa-book'><\/span><\/a><\/div><h4><a href='https:\/\/www.datanovia.com\/en\/product\/ggplot2-essentials-for-great-data-visualization-in-r\/' target='_blank'> Related Book <\/a><\/h4>GGPlot2 Essentials for Great Data Visualization in R<\/div>\n<div class='dt-sc-hr-invisible-medium  '><\/div>\n<div id=\"key-functions\" class=\"section level2\">\n<h2>Key functions<\/h2>\n<p>After installing and loading the ggplot2 package, you can use the following key functions:<\/p>\n<table>\n<thead>\n<tr class=\"header\">\n<th>Plot types<\/th>\n<th>GGPlot2 functions<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"odd\">\n<td>Initialize a ggplot<\/td>\n<td>ggplot()<\/td>\n<\/tr>\n<tr class=\"even\">\n<td>Scatter plot<\/td>\n<td>geom_point()<\/td>\n<\/tr>\n<tr class=\"odd\">\n<td>Box plot<\/td>\n<td>geom_boxplot()<\/td>\n<\/tr>\n<tr class=\"even\">\n<td>Violin plot<\/td>\n<td>geom_violin()<\/td>\n<\/tr>\n<tr class=\"odd\">\n<td>strip chart<\/td>\n<td>geom_jitter()<\/td>\n<\/tr>\n<tr class=\"even\">\n<td>Dot plot<\/td>\n<td>geom_dotplot()<\/td>\n<\/tr>\n<tr class=\"odd\">\n<td>Bar chart<\/td>\n<td>geom_bar() or geom_col()<\/td>\n<\/tr>\n<tr class=\"even\">\n<td>Line plot<\/td>\n<td>geom_line()<\/td>\n<\/tr>\n<tr class=\"odd\">\n<td>Histogram<\/td>\n<td>geom_histogram()<\/td>\n<\/tr>\n<tr class=\"even\">\n<td>Density plot<\/td>\n<td>geom_density()<\/td>\n<\/tr>\n<tr class=\"odd\">\n<td>Error bars<\/td>\n<td>geom_errorbar()<\/td>\n<\/tr>\n<tr class=\"even\">\n<td>QQ plot<\/td>\n<td>stat_qq()<\/td>\n<\/tr>\n<tr class=\"odd\">\n<td>ECDF plot<\/td>\n<td>stat_ecdf()<\/td>\n<\/tr>\n<tr class=\"even\">\n<td>Title and axis labels<\/td>\n<td>labs()<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div id=\"example-of-plots\" class=\"section level2\">\n<h2>Example of plots<\/h2>\n<p>The main function in the ggplot2 package is <code>ggplot()<\/code>, which can be used to initialize the plotting system with data and x\/y variables.<\/p>\n<p>For example, the following R code takes the <code>iris<\/code> data set to initialize the ggplot and then a layer (<code>geom_point()<\/code>) is added onto the ggplot to create a scatter plot of <code>x = Sepal.Length<\/code> by <code>y = Sepal.Width<\/code>:<\/p>\n<pre class=\"r\"><code>library(ggplot2)\r\nggplot(iris, aes(x = Sepal.Length, y = Sepal.Width))+\r\n  geom_point()\r\n\r\n# Change point size, color and shape\r\nggplot(iris, aes(x = Sepal.Length, y = Sepal.Width))+\r\n  geom_point(size = 1.2, color = \"steelblue\", shape = 21)<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/003-introduction-to-ggplot2-ggplot-scatter-plot-1.png\" width=\"288\" \/><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/003-introduction-to-ggplot2-ggplot-scatter-plot-2.png\" width=\"288\" \/><\/p>\n<p>Note that, in the code above, the shape of points is specified as number. The different point shape available in R, include:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/003-introduction-to-ggplot2-plotting-symbol-1.png\" width=\"288\" \/><\/p>\n<p>It\u2019s also possible to control points shape and color by a grouping variable (here, <code>Species<\/code>). For example, in the code below, we map points color and shape to the <code>Species<\/code> grouping variable.<\/p>\n<p>Note that, a ggplot can be holded in a variable, say <code>p<\/code>, to be printed later<\/p>\n<pre class=\"r\"><code># Control points color by groups\r\nggplot(iris, aes(x = Sepal.Length, y = Sepal.Width))+\r\n  geom_point(aes(color = Species, shape = Species))\r\n\r\n# Change the default color manually.\r\n# Use the scale_color_manual() function\r\np &lt;- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width))+\r\n  geom_point(aes(color = Species, shape = Species))+\r\n  scale_color_manual(values = c(\"#00AFBB\", \"#E7B800\", \"#FC4E07\"))\r\nprint(p)<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/003-introduction-to-ggplot2-ggplot-aesthetic-mapping-control-points-color-shape-and-size-1.png\" width=\"316.8\" \/><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/003-introduction-to-ggplot2-ggplot-aesthetic-mapping-control-points-color-shape-and-size-2.png\" width=\"316.8\" \/><\/p>\n<\/div>\n<div id=\"legend-position\" class=\"section level2\">\n<h2>Legend position<\/h2>\n<p>The default legend position is \u201cright\u201d. Use the function <code>theme()<\/code> with the argument <code>legend.position<\/code> to specify the legend position.<\/p>\n<p>Allowed values for the legend position include: \u201cleft\u201d, \u201ctop\u201d, \u201cright\u201d, \u201cbottom\u201d, \u201cnone\u201d.<\/p>\n<p>Examples:<\/p>\n<pre class=\"r\"><code># Change legend position to the top\r\np + theme(legend.position = \"top\")<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/003-introduction-to-ggplot2-change-legend-title-and-position-1.png\" width=\"316.8\" \/><\/p>\n<div class=\"warning\">\n<p>To remove legend, use <code>p + theme(legend.position = \u201cnone\u201d)<\/code>.<\/p>\n<\/div>\n<\/div>\n<div id=\"titles-and-axis-labels\" class=\"section level2\">\n<h2>Titles and axis labels<\/h2>\n<p>The function <code>labs()<\/code> can be used to change easily the main title, the subtitle, the axis labels and captions.<\/p>\n<pre class=\"r\"><code>p + labs(\r\n  title = \"Edgar Anderson's Iris Data\",\r\n  subtitle = \"iris is a data frame with 150 cases (rows) and 5 variables\",\r\n  x = \"Sepal Length (cm)\", y = \"Sepal Width (cm)\"\r\n  )<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/003-introduction-to-ggplot2-add-titles-and-axis-labels-1.png\" width=\"384\" \/><\/p>\n<\/div>\n<div id=\"facet-plot-with-multiple-pnels\" class=\"section level2\">\n<h2>Facet: Plot with multiple pnels<\/h2>\n<p>You can also split the plot into multiple panels according to a grouping variable. R function: <code>facet_wrap()<\/code>. Another interesting feature of ggplot2, is the possibility to combine multiple layers on the same plot. For example, with the following R code, we\u2019ll:<\/p>\n<ul>\n<li>Add points with <code>geom_point()<\/code>, colored by groups.<\/li>\n<li>Add the fitted smoothed regression line using <code>geom_smooth()<\/code>. By default the function <code>geom_smooth()<\/code> add the regression line and the confidence area. You can control the line color and confidence area fill color by groups.<\/li>\n<li>Facet the plot into multiple panels by groups<\/li>\n<li>Change color and fill manually using the function <code>scale_color_manual()<\/code> and <code>scale_fill_manual()<\/code><\/li>\n<\/ul>\n<pre class=\"r\"><code>ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width))+\r\n  geom_point(aes(color = Species))+               \r\n  geom_smooth(aes(color = Species, fill = Species))+\r\n  facet_wrap(~Species, ncol = 3, nrow = 1)+\r\n  scale_color_manual(values = c(\"#00AFBB\", \"#E7B800\", \"#FC4E07\"))+\r\n  scale_fill_manual(values = c(\"#00AFBB\", \"#E7B800\", \"#FC4E07\"))<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/003-introduction-to-ggplot2-ggplot-scatter-plot-with-regression-line-1.png\" width=\"624\" \/><\/p>\n<\/div>\n<div id=\"ggplot-theme\" class=\"section level2\">\n<h2>GGPlot theme<\/h2>\n<p>Note that, the default theme of ggplots is <code>theme_gray()<\/code> (or <code>theme_grey()<\/code>), which is theme with grey background and white grid lines. More themes are available for professional presentations or publications. These include: <code>theme_bw()<\/code>, <code>theme_classic()<\/code> and <code>theme_minimal()<\/code>.<\/p>\n<p>To change the theme of a given ggplot (p), use this: <code>p + theme_classic()<\/code>. To change the default theme to <code>theme_classic()<\/code> for all the future ggplots during your entire R session, type the following R code:<\/p>\n<pre class=\"r\"><code>theme_set(\r\n  theme_classic()\r\n)<\/code><\/pre>\n<p>Now you can create ggplots with <code>theme_classic()<\/code> as default theme:<\/p>\n<pre class=\"r\"><code>ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width))+\r\n  geom_point()<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/003-introduction-to-ggplot2-ggplot-examples-of-plots-1.png\" width=\"288\" \/><\/p>\n<\/div>\n<div id=\"further-customizations-of-a-ggplot\" class=\"section level2\">\n<h2>Further customizations of a ggplot<\/h2>\n<p>You can read more in our online ggplot cheatsheet, <a href=\"http:\/\/www.sthda.com\/english\/articles\/32-r-graphics-essentials\/125-ggplot-cheat-sheet-for-great-customization\/\">GGPlot Cheat Sheet for Great Customization<\/a>, which describes how to:<\/p>\n<ul>\n<li>Add title, subtitle, caption and change axis labels<\/li>\n<li>Change the appearance - color, size and face - of titles<\/li>\n<li>Set the axis limits<\/li>\n<li>Set a logarithmic axis scale<\/li>\n<li>Rotate axis text labels<\/li>\n<li>Change the legend title and position, as well, as the color and the size<\/li>\n<li>Change a ggplot theme and modify the background color<\/li>\n<li>Add a background image to a ggplot<\/li>\n<li>Use different color palettes: custom color palettes, color-blind friendly palettes, RColorBrewer palettes, viridis color palettes and scientific journal color palettes.<\/li>\n<li>Change point shapes (plotting symbols) and line types<\/li>\n<li>Rotate a ggplot<\/li>\n<li>Annotate a ggplot by adding straight lines, arrows, rectangles and text.<\/li>\n<\/ul>\n<\/div>\n<div id=\"save-ggplots\" class=\"section level2\">\n<h2>Save ggplots<\/h2>\n<p>You can export a ggplot to many file formats, including: PDF, SVG vector files, PNG, TIFF, JPEG, etc.<\/p>\n<p>The standard procedure to save any graphics from R is as follow:<\/p>\n<ol style=\"list-style-type: decimal;\">\n<li><strong>Open a graphic device<\/strong> using one of the following functions:<\/li>\n<\/ol>\n<ul>\n<li>pdf(\u201cr-graphics.pdf\u201d),<\/li>\n<li>svg(\u201cr-graphics.svg\u201d),<\/li>\n<li>png(\u201cr-graphics.png\u201d),<\/li>\n<li>tiff(\u201cr-graphics.tiff\u201d),<\/li>\n<li>jpeg(\u201cr-graphics.jpg\u201d),<\/li>\n<li>and so on.<\/li>\n<\/ul>\n<p>Additional arguments indicating the width and the height (in inches) of the graphics region can be also specified in the mentioned function.<\/p>\n<ol style=\"list-style-type: decimal;\" start=\"2\">\n<li><strong>Create and print a plot<\/strong><\/li>\n<li><strong>Close the graphic device<\/strong> using the function <code>dev.off()<\/code><\/li>\n<\/ol>\n<p>For example, to export ggplot2 graphs to a pdf file, the R code looks like this:<\/p>\n<pre class=\"r\"><code># Create some plots\r\nlibrary(ggplot2)\r\nmyplot1 &lt;- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + \r\n  geom_point()\r\nmyplot2 &lt;- ggplot(iris, aes(Species, Sepal.Length)) + \r\n  geom_boxplot()\r\n\r\n# Print plots to a pdf file\r\npdf(\"ggplot.pdf\")\r\nprint(myplot1)     # Plot 1 --&gt; in the first page of PDF\r\nprint(myplot2)     # Plot 2 ---&gt; in the second page of the PDF\r\ndev.off() <\/code><\/pre>\n<p>For printing to a <strong>png<\/strong> file, use:<\/p>\n<pre class=\"r\"><code>png(\"myplot.png\")\r\nprint(myplot)\r\ndev.off()<\/code><\/pre>\n<p>It\u2019s also possible to make a ggplot and to save it from the screen using the function <strong>ggsave()<\/strong>:<\/p>\n<pre class=\"r\"><code># 1. Create a plot: displayed on the screen (by default)\r\nggplot(mtcars, aes(wt, mpg)) + geom_point()\r\n# 2.1. Save the plot to a pdf\r\nggsave(\"myplot.pdf\")\r\n# 2.2 OR save it to png file\r\nggsave(\"myplot.png\")<\/code><\/pre>\n<\/div>\n<div id=\"conclusion\" class=\"section level2\">\n<h2>Conclusion<\/h2>\n<p>This article explains the basics of ggplot2 and shows how to export a ggplot to a PDF or PNG file.<\/p>\n<\/div>\n<div id=\"references\" class=\"section level2 unnumbered\">\n<h2>References<\/h2>\n<div id=\"refs\" class=\"references\">\n<div id=\"ref-R-ggplot2\">\n<p>Wickham, Hadley, Winston Chang, Lionel Henry, Thomas Lin Pedersen, Kohske Takahashi, Claus Wilke, Kara Woo, and Hiroaki Yutani. 2017. <em>Ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics<\/em>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><!--end rdoc--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article presents the basics of ggplot2. The key ggplot graphic functions are presented. You will learn how to build a ggplot piece by piece, as well as, how to customize and export the plot <\/p>\n","protected":false},"author":1,"featured_media":7917,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","class_list":["post-8312","dt_lessons","type-dt_lessons","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Best Introduction to GGPlot2 - Datanovia<\/title>\n<meta name=\"description\" content=\"This article presents the basics of ggplot2. The key ggplot graphic functions are presented. You will learn how to build a ggplot piece by piece, as well as, how to customize and export the plot\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Best Introduction to GGPlot2 - Datanovia\" \/>\n<meta property=\"og:description\" content=\"This article presents the basics of ggplot2. The key ggplot graphic functions are presented. You will learn how to build a ggplot piece by piece, as well as, how to customize and export the plot\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/\" \/>\n<meta property=\"og:site_name\" content=\"Datanovia\" \/>\n<meta property=\"article:modified_time\" content=\"2019-11-17T18:30:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_0789.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/\",\"name\":\"Best Introduction to GGPlot2 - Datanovia\",\"isPartOf\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_0789.jpg\",\"datePublished\":\"2018-12-30T12:11:15+00:00\",\"dateModified\":\"2019-11-17T18:30:35+00:00\",\"description\":\"This article presents the basics of ggplot2. The key ggplot graphic functions are presented. You will learn how to build a ggplot piece by piece, as well as, how to customize and export the plot\",\"breadcrumb\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/#primaryimage\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_0789.jpg\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_0789.jpg\",\"width\":1024,\"height\":512},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.datanovia.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Lessons\",\"item\":\"https:\/\/www.datanovia.com\/en\/lessons\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Introduction to GGPlot2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\",\"url\":\"https:\/\/www.datanovia.com\/en\/\",\"name\":\"Datanovia\",\"description\":\"Data Mining and Statistics for Decision Support\",\"publisher\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.datanovia.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\",\"name\":\"Datanovia\",\"url\":\"https:\/\/www.datanovia.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png\",\"width\":98,\"height\":99,\"caption\":\"Datanovia\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Best Introduction to GGPlot2 - Datanovia","description":"This article presents the basics of ggplot2. The key ggplot graphic functions are presented. You will learn how to build a ggplot piece by piece, as well as, how to customize and export the plot","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/","og_locale":"en_US","og_type":"article","og_title":"Best Introduction to GGPlot2 - Datanovia","og_description":"This article presents the basics of ggplot2. The key ggplot graphic functions are presented. You will learn how to build a ggplot piece by piece, as well as, how to customize and export the plot","og_url":"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/","og_site_name":"Datanovia","article_modified_time":"2019-11-17T18:30:35+00:00","og_image":[{"width":1024,"height":512,"url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_0789.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/","url":"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/","name":"Best Introduction to GGPlot2 - Datanovia","isPartOf":{"@id":"https:\/\/www.datanovia.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/#primaryimage"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_0789.jpg","datePublished":"2018-12-30T12:11:15+00:00","dateModified":"2019-11-17T18:30:35+00:00","description":"This article presents the basics of ggplot2. The key ggplot graphic functions are presented. You will learn how to build a ggplot piece by piece, as well as, how to customize and export the plot","breadcrumb":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/#primaryimage","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_0789.jpg","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_0789.jpg","width":1024,"height":512},{"@type":"BreadcrumbList","@id":"https:\/\/www.datanovia.com\/en\/lessons\/introduction-to-ggplot2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.datanovia.com\/en\/"},{"@type":"ListItem","position":2,"name":"Lessons","item":"https:\/\/www.datanovia.com\/en\/lessons\/"},{"@type":"ListItem","position":3,"name":"Introduction to GGPlot2"}]},{"@type":"WebSite","@id":"https:\/\/www.datanovia.com\/en\/#website","url":"https:\/\/www.datanovia.com\/en\/","name":"Datanovia","description":"Data Mining and Statistics for Decision Support","publisher":{"@id":"https:\/\/www.datanovia.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.datanovia.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.datanovia.com\/en\/#organization","name":"Datanovia","url":"https:\/\/www.datanovia.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png","width":98,"height":99,"caption":"Datanovia"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/"}}]}},"multi-rating":{"mr_rating_results":[]},"_links":{"self":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons\/8312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons"}],"about":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/types\/dt_lessons"}],"author":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/comments?post=8312"}],"version-history":[{"count":0,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons\/8312\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media\/7917"}],"wp:attachment":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media?parent=8312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}