Plots option

Discuss the jamovi platform, possible improvements, etc.
Post Reply
dannick9999
Posts: 2
Joined: Thu Dec 06, 2018 2:27 pm

Plots option

Post by dannick9999 »

is it possible to make the plots attached overlay? results are plotted in a way that suggests a measurement at different time points although we only had one measurement.

can this be quickly solved or is there a code for the plots that can be ran in the syntax mode?

many thanks!
Attachments
Screenshot 2018-12-06 at 15.28.59.png
Screenshot 2018-12-06 at 15.28.59.png (122.15 KiB) Viewed 2996 times
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Plots option

Post by jonathon »

hi, yes, although it's not that sexy at the moment.

here 'tis

Code: Select all

library(ggplot2)

data(ToothGrowth)

# run the analysis

results <- jmv::anova(
    data = ToothGrowth,
    dep = "len",
    factors = c("supp", "dose"),
    emMeans = list(
        c("dose", "supp")))


# get a theme, there's a few available

ggtheme <- jmvcore::theme_default()


# extract the image object from the results

image <- results$emm[[1]]$emmPlot


# image$state contains all the data to produce the plot
# the following is more or less copy/pasted from the jmv source code:

data <- as.data.frame(image$state$data)
emm <- image$state$emm
names <- image$state$names
labels <- image$state$labels

emm$lowerSE <- emm[[names$y]] - emm[['SE']]
emm$upperSE <- emm[[names$y]] + emm[['SE']]

# if (self$options$emmPlotData) {
    dodge <- position_dodge(0.7)
# } else {
#     dodge <- position_dodge(0.3)
# }

# OVERRIDE THE POSITION DODGE
dodge <- position_dodge(0)

if (is.null(names$lines)) {
    jitterdodge <- position_jitter(width = 0.1)
} else {
    jitterdodge <- position_jitterdodge(dodge.width = 0.7, jitter.width = 0.4)
}

p <- ggplot(data=emm, aes_string(x=names$x, y=names$y, color=names$lines, fill=names$lines, group=names$lines), inherit.aes = FALSE)

#if (self$options$emmPlotData)
    p <- p + geom_point(data=data, aes_string(y=labels$y), alpha=0.3, position=jitterdodge)

p <- p + geom_line(size=.8, position=dodge)

# if (self$options$emmPlotError == 'ci') {
    p <- p + geom_errorbar(aes_string(x=names$x, ymin=names$lower, ymax=names$upper), width=.1, size=.8, position=dodge)
# } else if (self$options$emmPlotError == 'se') {
#    p <- p + geom_errorbar(aes_string(x=names$x, ymin='lowerSE', ymax='upperSE'), width=.1, size=.8, position=dodge)
# }

p <- p + geom_point(shape=21, fill='white', size=3, position=dodge)

if ( ! is.null(names$plots)) {
    formula <- as.formula(paste(". ~", names$plots))
    p <- p + facet_grid(formula)
}

p <- p +
    labs(x=labels$x, y=labels$y, fill=labels$lines, color=labels$lines) +
    ggtheme + theme(panel.spacing = unit(2, "lines"))

p
Screen Shot 2018-12-07 at 10.01.49.png
Screen Shot 2018-12-07 at 10.01.49.png (789.65 KiB) Viewed 2986 times
dannick9999
Posts: 2
Joined: Thu Dec 06, 2018 2:27 pm

Re: Plots option

Post by dannick9999 »

thanks :) though this does not apply to rptd measures ANOVA :)
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Plots option

Post by jonathon »

oh sorry, you need to be more specific :)

let me know if you need a hand with it

cheers

jonathon
Post Reply