1

I'm trying to plot a dotplot using geom_dotplot in which each dot represents an observation of my data set. Therefore, the y-axis shouldn't represent density but actual counts. I'm aware of this thread which revolves around the same topic. However, I haven't managed to solve my issue following the same methodology.

df <- data.frame(x = sample(1:500, size = 150, replace = TRUE))

ggplot(df, aes(x)) +
  geom_dotplot(method = 'histodot', binwidth = 1)

And I obtain the following graph enter image description here, I want to obtain one similar to this one one where I can manipulate dots' size, space between, etc.

Thanks in advance

PabloAB
  • 233
  • 1
  • 6
  • As a starting point, is this closer to what you're looking for? `ggplot(df) + geom_dotplot(aes(x=x))` – Christopher Belanger Jan 04 '22 at 20:12
  • Yes Christopher, it was a typo. Thanks – PabloAB Jan 04 '22 at 20:33
  • Each dot should represent an individual observation. You can control the width of them with the binwidth argument. By decreasing bindwidth, you get taller stacks of wider dots, but the total number of dots should be the same. Unfortunately, the y-axis produced by geom_dotplot() is fully abstract as far as I can tell. I've experimented with trying to scale it and set the limits manually (because geom_dotplot often does a poor job) but I can't figure it out. I've had to settle for setting the y-axis limits manually. – Arthur Jan 05 '22 at 17:46
  • Thank you Arthur. I have a better idea of binwidth. – PabloAB Jan 06 '22 at 00:16

1 Answers1

0

You can modify the binwidth argument to cause the points to stack. For example,

df %>%
  ggplot(aes(x = x)) +
  geom_dotplot(method = "histodot", binwidth = 20)

enter image description here

There is a dotsize argument that can be used to modify the size of the dot.

cazman
  • 1,452
  • 1
  • 4
  • 11