ACCLAB/dabestr

Error in `levels<-`(`*tmp*`, value = as.character(levels)) : factor level [5] is duplicated

matasV99 opened this issue · 3 comments

Hi,

I am trying to run your Cummings estimation plot for multiple group comparison but i am running into the error in the name of this issue.

Here is a reproducible example:
df <- data.frame (first_column = c(0.5, 0.55, 0.65, 0.64, 0.6125, 0.6, 0.525, 0.6125, 0.4375, 0.475, 0.525, 0.425, 0.6, 0.54, 0.64, 0.58),
second_column = c("O pre", "O pre", "O pre", "O pre", "Sham pre", "Sham pre", "Sham pre", "Sham pre", "Sham after", "Sham after", "Sham after", "Sham after", "O after", "O after", "O after", "O after" )
)
colnames(df)[1] <- "light"
colnames(df)[2] <- "condition"

multi.two.group.unpaired <- df %>% dabest(condition, light,
idx = list(c("O pre", "O after"),
c("Sham pre", "Sham after"),
c("Sham after", "O after")),
paired = FALSE)
multi.two.group.unpaired.meandiff <- mean_diff(multi.two.group.unpaired)
plot(multi.two.group.unpaired.meandiff)

Thank you for your time,
Matas

Hi Matas,

Unfortunately the plotting function is unable to plot repeated groups directly .

You will want to duplicate the repeated columns, so something like

df <- data.frame(first_column = c(0.5, 0.55, 0.65, 0.64, 
                                    0.6125, 0.6, 0.525, 0.6125, 
                                    0.4375, 0.475, 0.525, 0.425, 
                                    0.6, 0.54, 0.64, 0.58,
                                    0.4375, 0.475, 0.525, 0.425, 
                                    0.6, 0.54, 0.64, 0.58 ),

                 second_column = c("O pre", "O pre", "O pre", "O pre", 
                                   "Sham pre", "Sham pre", "Sham pre", "Sham pre", 
                                   "Sham after", "Sham after", "Sham after", "Sham after", 
                                   "O after", "O after", "O after", "O after" ,
                                   "Sham after2",  "Sham after2", "Sham after2", "Sham after2", 
                                   "O after2", "O after2", "O after2", "O after2" )
)        

colnames(df)[1] <- "light"
colnames(df)[2] <- "condition"

followed by

multi.two.group.unpaired <- df %>% dabest(condition, light,
                                                  idx = list(c("O pre", "O after"),
                                                             c("Sham pre", "Sham after"),
                                                             c("Sham after2", "O after2")),
                                                  paired = FALSE)
multi.two.group.unpaired.meandiff <- mean_diff(multi.two.group.unpaired)
plot(multi.two.group.unpaired.meandiff)

You can use a vector graphics software to edit the x-axis labels.
Hope this helps!

Dear Josesho,

Thank you so much! May I inquire what exactly you mean by vector graphics software? I understand dabest uses ggplot, however, I was unable to change the axis labels or labels by just adding ggplot objects to dabest objects...

Thank you again for your answer this is very helpful,
Matas

Vector graphics software are software that can directly edit SVG output, such as Adobe Illustrator, and Inkscape. So you'd produce the estimation graph to SVG, then open it in a vector graphics software, and directly edit the text. Not ideal, but solves the problem!