Share the Gallery !Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone

A bubble plot is almost the same thing as a Scatterplot. It represents the relationship between 2 numerical variables. The bubble plot adds a third dimension: a third variable is mapped to the size of the points. It provides additional information to the plot.

Fortunately, ggplot2 allows to easily make the link between the column of a data frame and the size of dots. You just have to add it in the aesthetic call of the geom_point(). Here we start with a basic scatterplot, representing the relationship between 2 columns of the diamonds data set: ‘carat’ (the weight of diamonds) and ‘price’. Then, we map the depth to the size:

 

 

 

Once you understand this concept, you probably want to control the size of the smallest and biggest bubbles. It is possible using the scale_size_continuous facility. Note that you can even apply a transformation to the size variable. It can be handy if you want to highlight the highest values for example:

 

 

 

 

 

 

 

Note that you can go even further and add a fourth dimension using colour. But be careful, if you add to much information on the same graphic, it gets hard to get the message. You can also use color to highlight one of the axis (but in this case you don’t need to show it in the legend).

 

 

 

 

 

 

Last but not least, don’t forget to have a look to the ggplot2 section of the gallery to learn how to customise your plot. Here is an example of appearance you can get with a few additional lines of code:

 

 

Related


 

Make a search


 

 


Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz