{"id":8373,"date":"2019-01-06T00:08:13","date_gmt":"2019-01-05T22:08:13","guid":{"rendered":"https:\/\/www.datanovia.com\/en\/?p=8373"},"modified":"2019-12-25T11:04:51","modified_gmt":"2019-12-25T09:04:51","slug":"how-to-create-a-bubble-chart-in-r-using-ggplot2","status":"publish","type":"post","link":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/","title":{"rendered":"How to Create a Bubble Chart in R using GGPlot2"},"content":{"rendered":"<div id=\"rdoc\">\n<p>In this article, you will learn how to create a <strong>bubble chart in R<\/strong> using the ggplot2 package.<\/p>\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=\"prerequisites\" class=\"section level2\">\n<h2>Prerequisites<\/h2>\n<ul>\n<li>Load the ggplot2 package and set the theme function <code>theme_bw()<\/code> as the default theme:<\/li>\n<\/ul>\n<pre class=\"r\"><code>library(ggplot2)\r\ntheme_set(\r\n  theme_bw() + \r\n    theme(legend.position = \"top\")\r\n  )<\/code><\/pre>\n<ul>\n<li>Data preparation<\/li>\n<\/ul>\n<p>Demo dataset: <code>mtcars<\/code>. The variable <code>cyl<\/code> is used as grouping variable.<\/p>\n<pre class=\"r\"><code># Load data\r\ndata(\"mtcars\")\r\ndf &lt;- mtcars\r\n\r\n# Convert cyl as a grouping variable\r\ndf$cyl &lt;- as.factor(df$cyl)\r\n\r\n# Inspect the data\r\nhead(df[, c(\"wt\", \"mpg\", \"cyl\", \"qsec\")], 4)<\/code><\/pre>\n<pre><code>##                  wt  mpg cyl qsec\r\n## Mazda RX4      2.62 21.0   6 16.5\r\n## Mazda RX4 Wag  2.88 21.0   6 17.0\r\n## Datsun 710     2.32 22.8   4 18.6\r\n## Hornet 4 Drive 3.21 21.4   6 19.4<\/code><\/pre>\n<\/div>\n<div id=\"create-a-bubble-chart\" class=\"section level2\">\n<h2>Create a bubble chart<\/h2>\n<p>In a bubble chart, points <code>size<\/code> is controlled by a continuous variable, here <code>qsec<\/code>. In the R code below, the argument alpha is used to control color transparency. alpha should be between 0 and 1.<\/p>\n<pre class=\"r\"><code>ggplot(df, aes(x = wt, y = mpg)) + \r\n  geom_point(aes(color = cyl, size = qsec), alpha = 0.5) +\r\n  scale_color_manual(values = c(\"#00AFBB\", \"#E7B800\", \"#FC4E07\")) +\r\n  scale_size(range = c(0.5, 12))  # Adjust the range of points size<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/120-ggplot-bubble-chart-in-r-bubble-chart-1.png\" width=\"480\" \/><\/p>\n<\/div>\n<\/div>\n<p><!--end rdoc--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, you will learn how to create a bubble chart in R using the ggplot2 package. Prerequisites Load the ggplot2 package and set the theme function theme_bw() as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7816,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rating_form_position":"","rating_results_position":"","mr_structured_data_type":"","footnotes":""},"categories":[124],"tags":[131],"class_list":["post-8373","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ggplot2","tag-ggplot2-faq"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Create a Bubble Chart in R using GGPlot2 - Datanovia<\/title>\n<meta name=\"description\" content=\"In this article, you will learn how to create a bubble chart in R using the ggplot2 package.\" \/>\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\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create a Bubble Chart in R using GGPlot2 - Datanovia\" \/>\n<meta property=\"og:description\" content=\"In this article, you will learn how to create a bubble chart in R using the ggplot2 package.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/\" \/>\n<meta property=\"og:site_name\" content=\"Datanovia\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-05T22:08:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-12-25T09:04:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030284.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=\"author\" content=\"Alboukadel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alboukadel\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/\"},\"author\":{\"name\":\"Alboukadel\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/7767cf2bd5c91a1610c6eb53a0ff069e\"},\"headline\":\"How to Create a Bubble Chart in R using GGPlot2\",\"datePublished\":\"2019-01-05T22:08:13+00:00\",\"dateModified\":\"2019-12-25T09:04:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/\"},\"wordCount\":132,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030284.jpg\",\"keywords\":[\"ggplot2 FAQ\"],\"articleSection\":[\"ggplot2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/\",\"name\":\"How to Create a Bubble Chart in R using GGPlot2 - Datanovia\",\"isPartOf\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030284.jpg\",\"datePublished\":\"2019-01-05T22:08:13+00:00\",\"dateModified\":\"2019-12-25T09:04:51+00:00\",\"description\":\"In this article, you will learn how to create a bubble chart in R using the ggplot2 package.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#primaryimage\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030284.jpg\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030284.jpg\",\"width\":1024,\"height\":512},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.datanovia.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create a Bubble Chart in R using 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\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/7767cf2bd5c91a1610c6eb53a0ff069e\",\"name\":\"Alboukadel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ed3108646c5c7c3d188324ab972f96ad7d9975b41b94014d7f68257791be395a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ed3108646c5c7c3d188324ab972f96ad7d9975b41b94014d7f68257791be395a?s=96&d=mm&r=g\",\"caption\":\"Alboukadel\"},\"url\":\"https:\/\/www.datanovia.com\/en\/blog\/author\/kassambara\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Create a Bubble Chart in R using GGPlot2 - Datanovia","description":"In this article, you will learn how to create a bubble chart in R using the ggplot2 package.","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\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/","og_locale":"en_US","og_type":"article","og_title":"How to Create a Bubble Chart in R using GGPlot2 - Datanovia","og_description":"In this article, you will learn how to create a bubble chart in R using the ggplot2 package.","og_url":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/","og_site_name":"Datanovia","article_published_time":"2019-01-05T22:08:13+00:00","article_modified_time":"2019-12-25T09:04:51+00:00","og_image":[{"width":1024,"height":512,"url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030284.jpg","type":"image\/jpeg"}],"author":"Alboukadel","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Alboukadel","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#article","isPartOf":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/"},"author":{"name":"Alboukadel","@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/7767cf2bd5c91a1610c6eb53a0ff069e"},"headline":"How to Create a Bubble Chart in R using GGPlot2","datePublished":"2019-01-05T22:08:13+00:00","dateModified":"2019-12-25T09:04:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/"},"wordCount":132,"commentCount":0,"publisher":{"@id":"https:\/\/www.datanovia.com\/en\/#organization"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030284.jpg","keywords":["ggplot2 FAQ"],"articleSection":["ggplot2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/","url":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/","name":"How to Create a Bubble Chart in R using GGPlot2 - Datanovia","isPartOf":{"@id":"https:\/\/www.datanovia.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#primaryimage"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030284.jpg","datePublished":"2019-01-05T22:08:13+00:00","dateModified":"2019-12-25T09:04:51+00:00","description":"In this article, you will learn how to create a bubble chart in R using the ggplot2 package.","breadcrumb":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#primaryimage","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030284.jpg","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030284.jpg","width":1024,"height":512},{"@type":"BreadcrumbList","@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-a-bubble-chart-in-r-using-ggplot2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.datanovia.com\/en\/"},{"@type":"ListItem","position":2,"name":"How to Create a Bubble Chart in R using 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\/"}},{"@type":"Person","@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/7767cf2bd5c91a1610c6eb53a0ff069e","name":"Alboukadel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ed3108646c5c7c3d188324ab972f96ad7d9975b41b94014d7f68257791be395a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ed3108646c5c7c3d188324ab972f96ad7d9975b41b94014d7f68257791be395a?s=96&d=mm&r=g","caption":"Alboukadel"},"url":"https:\/\/www.datanovia.com\/en\/blog\/author\/kassambara\/"}]}},"multi-rating":{"mr_rating_results":[]},"_links":{"self":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/posts\/8373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/types\/post"}],"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=8373"}],"version-history":[{"count":1,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/posts\/8373\/revisions"}],"predecessor-version":[{"id":8374,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/posts\/8373\/revisions\/8374"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media\/7816"}],"wp:attachment":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media?parent=8373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/categories?post=8373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/tags?post=8373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}