1

I have been struggling with this for a while. I am trying to create a set of "box and whisker"-plots and add in the individual data points with ggplot2. Basically I am using a loop to create multiple independent plots out of a given data set.

I am getting what I want. However, between the different plots, the size of the dots vary considerably:

small dots

enter image description here

vs large dots.

enter image description here

From what I understand, the dotsize depends on the binwidths. But even if I set a certain binwidth and choose method=histodot instead of the default, this doesn't change. Any ideas how to set the dots to a fixed size?

Here an excerpt of the code, which is execute for the plot in every loop:

p <- ggplot(data=t, mapping=aes(x=get(feature, t), y=get(response, t)));
p <- p + geom_boxplot(alpha = 0, size=0.2, width=0.4); 
p <- p + geom_dotplot(alpha=0.7, aes(color=get(feature, t), fill=get(feature, t)) ,binaxis="y",stackdir="center", bindwidth=5, method=histodot, dotsize=2);
p <- p + guides(colour =FALSE, fill=FALSE);
p <- p + facet_wrap(grouping, ncol=1, nrow=1);
ggsave(paste(s, ".pdf", sep=""), plot=p);

Thank you!

EDIT: Here's a sample data set and a the code (graphs will look different from the example, but problem remains the same).

function(x, feature="Modification", response="FC", grouping="Sequence", alpha = 0.05, plot=TRUE )
{
    for(s in unique(get(grouping, x)))
    {
        t <- x[get(grouping, x) == s,];
        if( (length(unique(get(feature, t))) > 1) && (length(unique(get(feature, t))) < length(get(feature, t))) )
        {
            y <- (anova(aov(get(response, t) ~ get(feature, t), data = t)));
            if(y$"Pr(>F)"[1] < alpha)
            {
                print(t[1,1:2]);
                print(y);
                if(plot)
                {
                    p <- ggplot(data=t, mapping=aes(x=get(feature,t), y=get(response, t)));
                    p <- p + geom_boxplot(alpha = 0, size=0.2, width=0.4); 
                    p <- p + geom_dotplot(alpha=0.7, aes(color=get(feature, t), fill=get(feature, t)) ,binaxis="y",stackdir="center", binwidth=0.05, method="histodot", dotsize=0.8);
                    p <- p + guides(colour =FALSE, fill=FALSE);
                    p <- p + facet_wrap(grouping, ncol=1, nrow=1);
                    ggsave(paste(s, ".pdf", sep=""), plot=p);
                }
            }
        }
    }
}
Philipp
  • 11
  • 2
  • 2
    Hi Philipp, it will save time for answerers if you provide a minimal dataset which can be used to run your code. Check out this [question](https://stackoverflow.com/a/5963610/3277050) for some tricks that make it easy – see24 Aug 28 '18 at 17:44
  • Maybe `geom_jitter` would be better for this – S Rivero Aug 28 '18 at 17:48
  • Thanks for the quick replies. Rivero, I have tried jitter. It would be my backup option. However, I don't have a very high density of data points so jitterplots often look a bit irregular, thus I prefer the look of dotplots. I would just like to get the consistent. See24: Ok, I will prepare a dataset and the proper code to try it out. Will take me until tomorrow evening. Just thought, maybe someone bumpt into the same problem before and had a straight answer. That's why I didn't give one straight away. – Philipp Aug 28 '18 at 21:03

0 Answers0