Hey everybody,

this is just a short post but I found it very useful. I want to show you how to add images as a background to your ggplot2 plots.

To do so we need the packages png and grid

 

Btw, this is just a cool and fast way to import different packages at once.

As an example for a background image plot I used the Sochi Olympic Medals plot by TRinker, which looks really good.

The tutorial shows you how to create a plot based on the current medals scores which looks like this:

sochi olympic games viz

Add an image

First of all we need to load the picture. Just place it in your working directory and load it with:

And add a raster:

And that´s nearly all!

Now we just have to add it with the annotation_custom() function to our plot.

The result will look like this:

sochi rstats image png gglot2

Previous articleDownload LinkedIn contacts with Python
Next articleUsing Google BigQuery with R
During my time at university and learning about the basics of economics I started heavily exploring the possibilities and changes caused by digital disruptions and the process of digital transformation, whereby I focused on the importance of data and data analytics and combination with marketing and management. My personal focus of interest lies heavily on technology, digital marketing and data analytics. I made early acquaintance with programming and digital technology and never stop being interested in following the newest innovations. I am an open, communicative and curious person. I enjoy writing, blogging and speaking about technology.
  • http://danganothererror.wordpress.com danganothererror

    I wonder why some of the points (first pic) are not on the horizontal line. I don’t see any jitter commands anywhere?

    • http://thinktostart.wordpress.com julianhi

      Oh you are right. The first screenshot used a jitter graph I played around with. I will change the screenshot. Thanks for your comment.
      Regards

  • Pingback: Add a background png image to ggplot2 | nishant@analyst()

  • Sandra

    cool tutorial! thanks for putting it on here!

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Thank you!