0

I have 5 datasets, each with a value column and a group column.

data

Each dataset has a different 'group' value. They're joined together to make 1 big dataset, each clearly separated by its 'group' value

I'm trying to create a dotplot that neatly separates the groups by themselves, kind of like the following, where the M and F groups are clearly separated:
ideal dotplot

What I currently have, however, is the following: current plot

Since most of the datapoints sit around the 2-3 range, they are stacked above each other and the resulting plot has datapoints that are overflowing to the other groups

This is the plotting code I'm currently using:

p<-ggplot(new_df, aes(x=group, y=ploidy)) + 
  geom_dotplot(binaxis='y', stackdir='centerwhole', binwidth = 0.5, position = "dodge", stackgroups = TRUE, dotsize = 0.2)

ggplot(new_df, aes(x=group, y=ploidy)) + 
  geom_dotplot(binaxis='y', stackdir='centerwhole',
               stackratio=1.5, dotsize=0.2, stackgroups = TRUE)
p + scale_x_discrete(limits=c("1", "2", "3", "4", "5"))
p + stat_summary(fun=median, geom="point", shape=18,
                 size=3, color="red")

Can anyone help point out what mistake I'm making and how to fix it? I've tried tweaking many different parameters and following the documentation but R isn't my main language and I'm running into trouble. Any help would be appreciated, thank you.

Samer Baslan
  • 29
  • 1
  • 7
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. Do not share data as an images because we cannot copy/paste that into R for testing. It looks like you just have too many repeated values in your data to make sense of a dotplot. If you want general data visualization advice, the better place to ask for help is [stats.se] – MrFlick Feb 25 '22 at 07:44
  • without example data it's hard to tell but I could imagine that your `group` variable is of type `numeric` when it should actually be a `factor`. Does your plot look better when you set `aes(x=factor(group)), ...`? – RamsesII Feb 25 '22 at 10:50
  • @RamsesII no, I did change it to a factor, so that shouldn't be it. I will try to post on Cross Validated with a reproducible example. – Samer Baslan Feb 25 '22 at 18:45

0 Answers0