I am using an r data frame which looks something like:
df = data_frame(
A=c(sample(0:2,size=50,replace=TRUE)),
A1=c(sample(0:50,size=50,replace=TRUE)),
A2=c(sample(0:50,size=50,replace=TRUE)))
I am trying to produce a grouped dot plot of A1 and A1, grouped by A, e.g:
To produce this I've converted the data from wide to long format using the below code and then utlised position_dodge
library(reshape2)
df2 <- melt(df, id.vars=c("A"))
I'm trying to work out how to draw the equivalent graph without converting the format. My current code is:
library(ggplot2)
ggplot(df,aes(x=as.factor(A)))+
xlab("A") +
ylab("Score") +
geom_dotplot (aes(y=A1), binaxis="y",binwidth=1, stackdir = "center",fill="#5ec962",colour="#5ec962") +
stat_summary(aes(y=A1),fun = median, fun.min = median, fun.max = median, geom = "crossbar", width = 0.2,colour="#5ec962") +
geom_dotplot (aes(y=A2), binaxis="y",binwidth=1, stackdir = "center",fill="#3b528b",colour="#3b528b") +
stat_summary(aes(y=A2),fun = median, fun.min = median, fun.max = median, geom = "crossbar", width = 0.2,colour="#3b528b") +
theme_classic()
This has the two groups on top of each other like this:
Is there a way to produce a graph like the first one with the groups side by side without converting the format? I'm planning to look at multiple comparison and would ideally not keep doing conversions.
Thank you.