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:
vs large dots.
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);
}
}
}
}
}