Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading