How to create a bubble chart in R? A bubble chart is a variant of the scatter plot where we compare the relationship between two continuous variables with one additional variable of size, that is the size of each data point. A bubble chart is a two-dimensional data visualization chart that displays data in the form of circles (bubbles). A bubble chart takes three variables of the data, namely the size of the bubble, horizontal and vertical location of the data points. This recipe demonstrates an example of a bubble chart using ggplot.
**Syntax for bubble plot is-ggplot (data, aes (x,y, size))+geom_point ()** where, data — the required data to plot bubble chart aes (x=data,y=data,size)) — the aes function — creates bubble from data to geom geom_point — the geometric object to be drawn — bubble
# define two variables data = data.frame (x_data =c(2,4,6,8,10,12), y_data = c(10,20,30,40,50,60)) print(data)
ggplot(data, aes(x=x_data, y=y_data, size = x_data,col=x_data)) +geom_point() # the size of bubble differs as value increases the size of the bubbles/circles increases.