Skip navigation

High resolution and SVG versions of the new R logo are finally available.

I converted the SVG to WKT (file here) which means we can use it like we would a shapefile in R. That includes plotting!

Here’s a short example of how to read that WKT and plot the logo using ggplot2:

library(sp)
library(maptools)
library(rgeos)
library(ggplot2)
library(ggthemes)
 
r_wkt_gist_file <- "https://gist.githubusercontent.com/hrbrmstr/07d0ccf14c2ff109f55a/raw/db274a39b8f024468f8550d7aeaabb83c576f7ef/rlogo.wkt"
if (!file.exists("rlogo.wkt")) download.file(r_wkt_gist_file, "rlogo.wkt")
rlogo <- readWKT(paste0(readLines("rlogo.wkt", warn=FALSE)))
 
rlogo_shp <- SpatialPolygonsDataFrame(rlogo, data.frame(poly=c("halo", "r")))
rlogo_poly <- fortify(rlogo_shp, region="poly")
 
ggplot(rlogo_poly) + 
  geom_polygon(aes(x=long, y=lat, group=id, fill=id)) + 
  scale_fill_manual(values=c(halo="#b8babf", r="#1e63b5")) +
  coord_equal() + 
  theme_map() + 
  theme(legend.position="none")

RStudio

5 Comments

  1. Wow. But you could just do it in base much more easily using plot. Just replace the ggplot() nonsense with:

    plot(rlogo_shp, col=c(“#b8babf”, “#1e63b5”), lty=0)

    • I will (grudgingly :-) award base plotting a singular advantage over ggplot2 here :-)

      Having said that, “base” is getting help from an inherited sp::plot method for the SpatialPolygonsDataFrame class which ends up calling the S4 method for plotting SpatialPolygons which is actually doing far more work than you may realize under the covers: https://github.com/cran/sp/blob/master/R/SpatialPolygons-displayMethods.R.

      So, you’re really saying that the sp pkg authors failed to make a set of autoplot() S3 methods for Spatial… objects to give ggplot2 users the same crutch base graphics users already have :-)

  2. Neat!

  3. Hello,

    I am looking into Rlogo use. It is licensed CC-BY-SA (https://www.r-project.org/logo/), any way to automatically insert the needed links and reference in the caption ?


One Trackback/Pingback

  1. […] article was first published on R – rud.is, and kindly contributed to […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.