Search code examples
rggplot2bubble-chart

Create plot with only x axis


I want to create a bubble plot without the y axis, meaning the x axis represents a range between certain values and the size of the bubbles corresponds to a "number" variable.

Since geom_point() requires a y variable, I created a new column with only zero values and assigned it to the y axis.

ggplot(df, aes(x=range, y=new, size = numberPoints)) +
    geom_point(alpha=0.5, shape=19) +
    scale_size(range = c(.1, 24)) +
    scale_y_continuous(breaks = NULL)

However, it gave the following result (the y axis is too large):

enter image description here

I only wanted the bubbles above the x axis (without too much space), but I can't find a way to do it.


Solution

  • You can use coord_fixed to "reduce" your axis

    library(dplyr)
    library(ggplot2)
    
    data.frame(x = c(1,2,3,4), size = c(1,1,4,8)) %>% 
      ggplot(aes(x=x, y=1, size = size)) +
      geom_point(alpha=0.5, shape=19) +
      scale_size(range = c(.1, 24)) +
      scale_y_continuous(breaks = NULL)+
      coord_fixed(6)
    

    enter image description here