{"id":8432,"date":"2019-01-16T03:02:20","date_gmt":"2019-01-16T01:02:20","guid":{"rendered":"https:\/\/www.datanovia.com\/en\/?p=8432"},"modified":"2019-12-25T10:54:45","modified_gmt":"2019-12-25T08:54:45","slug":"how-to-create-icon-in-r","status":"publish","type":"post","link":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/","title":{"rendered":"How to Create Icon in R"},"content":{"rendered":"<p>&nbsp;<\/p>\n<div id=\"rdoc\">\n<div id=\"create-icon\" class=\"section level1\">\n<h1>Create Icon in R<\/h1>\n<p>This article describes how to <strong>create icon in R<\/strong> with transparent background from a ggplot.<\/p>\n<p>Contents:<\/p>\n<div id=\"prerequisites\" class=\"section level2\">\n<h2>Prerequisites<\/h2>\n<p>Load ggplot2 and create a helper theme for ggplot icon:<\/p>\n<pre class=\"r\"><code>library(ggplot2)\r\n\r\n# Helper theme for ggplot icon\r\ntheme_icon &lt;- function () {\r\n    theme_void() + \r\n    theme(\r\n      panel.background = element_rect(fill = \"transparent\", colour = NA), \r\n      plot.background = element_rect(fill = \"transparent\", colour = NA), \r\n      legend.background = element_rect(fill = \"transparent\", colour = NA), \r\n      legend.box.background = element_rect(fill = \"transparent\", colour = NA)\r\n    )\r\n}<\/code><\/pre>\n<\/div>\n<div id=\"create-an-icon\" class=\"section level2\">\n<h2>Create an icon<\/h2>\n<ul>\n<li>Create an icon form a ggplot graphic<\/li>\n<\/ul>\n<pre class=\"r\"><code>p &lt;- ggplot(iris, aes(Species, Sepal.Length)) + \r\n  geom_boxplot(color = \"#478bca\", fill = \"transparent\") +\r\n  theme_icon()<\/code><\/pre>\n<ul>\n<li>Save the icon into a 72x72 pixel png or svg format:<\/li>\n<\/ul>\n<pre class=\"r\"><code># SVG\r\nggsave(\r\n  filename = \"figures\/boxplot-icon_72px.svg\", p, \r\n  dpi=72, width = 1, height = 1\r\n  )\r\n\r\n# PNG\r\nggsave(\r\n  filename = \"figures\/boxplot-icon_72px.png\", p, \r\n  dpi=72, width = 1, height = 1, bg = \"transparent\"\r\n  )<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/r-tutorial\/images\/boxplot-icon_72px.svg\" width=\"20%\" \/><\/p>\n<\/div>\n<div id=\"create-an-icon-with-hexagon-sticker\" class=\"section level2\">\n<h2>Create an icon with hexagon sticker<\/h2>\n<p>We\u2019ll use the <a href=\"https:\/\/github.com\/GuangchuangYu\/hexSticker\">hexSticker<\/a> R package. <code>imageMagick<\/code> is required for installing hexSticker. If you have not installed it, please try the <a href=\"https:\/\/www.imagemagick.org\/script\/download.php\">following approaches<\/a>.<\/p>\n<pre class=\"r\"><code>library(hexSticker)\r\np &lt;- ggplot(iris, aes(Species, Sepal.Length)) + \r\n  geom_boxplot(color = \"white\", fill = \"transparent\") +\r\n  theme_icon()\r\np.sticker &lt;- sticker(\r\n  p, package=\" \", p_size=3, \r\n  s_x=1, s_y=1.1, s_width=1.3, s_height=1.5,\r\n  h_color = \"#478bca\", h_fill = \"#478bca\",\r\n  filename=\"figures\/boxplot-icon-sticker.png\"\r\n  )<\/code><\/pre>\n<pre class=\"r\"><code>p.sticker<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/r-tutorial\/images\/boxplot-icon-sticker.png\" width=\"192\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!--end rdoc--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Create Icon in R This article describes how to create icon in R with transparent background from a ggplot. Contents: Prerequisites Load ggplot2 and create a helper theme for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7877,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rating_form_position":"","rating_results_position":"","mr_structured_data_type":"","footnotes":""},"categories":[126],"tags":[],"class_list":["post-8432","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r-tips-and-tricks"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Create Icon in R: Best Tips - Datanovia<\/title>\n<meta name=\"description\" content=\"This article describes how to create icon in R with transparent background from a ggplot.\" \/>\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-icon-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Icon in R: Best Tips - Datanovia\" \/>\n<meta property=\"og:description\" content=\"This article describes how to create icon in R with transparent background from a ggplot.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Datanovia\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-16T01:02:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-12-25T08:54:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_7132.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-icon-in-r\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/\"},\"author\":{\"name\":\"Alboukadel\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/7767cf2bd5c91a1610c6eb53a0ff069e\"},\"headline\":\"How to Create Icon in R\",\"datePublished\":\"2019-01-16T01:02:20+00:00\",\"dateModified\":\"2019-12-25T08:54:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/\"},\"wordCount\":88,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_7132.jpg\",\"articleSection\":[\"R Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/\",\"name\":\"How to Create Icon in R: Best Tips - Datanovia\",\"isPartOf\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_7132.jpg\",\"datePublished\":\"2019-01-16T01:02:20+00:00\",\"dateModified\":\"2019-12-25T08:54:45+00:00\",\"description\":\"This article describes how to create icon in R with transparent background from a ggplot.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#primaryimage\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_7132.jpg\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_7132.jpg\",\"width\":1024,\"height\":512},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.datanovia.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Icon in R\"}]},{\"@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 Icon in R: Best Tips - Datanovia","description":"This article describes how to create icon in R with transparent background from a ggplot.","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-icon-in-r\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Icon in R: Best Tips - Datanovia","og_description":"This article describes how to create icon in R with transparent background from a ggplot.","og_url":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/","og_site_name":"Datanovia","article_published_time":"2019-01-16T01:02:20+00:00","article_modified_time":"2019-12-25T08:54:45+00:00","og_image":[{"width":1024,"height":512,"url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_7132.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-icon-in-r\/#article","isPartOf":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/"},"author":{"name":"Alboukadel","@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/7767cf2bd5c91a1610c6eb53a0ff069e"},"headline":"How to Create Icon in R","datePublished":"2019-01-16T01:02:20+00:00","dateModified":"2019-12-25T08:54:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/"},"wordCount":88,"commentCount":0,"publisher":{"@id":"https:\/\/www.datanovia.com\/en\/#organization"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_7132.jpg","articleSection":["R Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/","url":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/","name":"How to Create Icon in R: Best Tips - Datanovia","isPartOf":{"@id":"https:\/\/www.datanovia.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#primaryimage"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_7132.jpg","datePublished":"2019-01-16T01:02:20+00:00","dateModified":"2019-12-25T08:54:45+00:00","description":"This article describes how to create icon in R with transparent background from a ggplot.","breadcrumb":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#primaryimage","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_7132.jpg","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_7132.jpg","width":1024,"height":512},{"@type":"BreadcrumbList","@id":"https:\/\/www.datanovia.com\/en\/blog\/how-to-create-icon-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.datanovia.com\/en\/"},{"@type":"ListItem","position":2,"name":"How to Create Icon in R"}]},{"@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\/8432","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=8432"}],"version-history":[{"count":4,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/posts\/8432\/revisions"}],"predecessor-version":[{"id":11637,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/posts\/8432\/revisions\/11637"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media\/7877"}],"wp:attachment":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media?parent=8432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/categories?post=8432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/tags?post=8432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}