rggplot2experimental-design

Main Effect plot with ggplot2


I am new to R and ggplot2. I would like to create a main effect plot for a full-factorial experiment I did.

The plot should take the mean of the low level and plot a line to the mean of the high level. As of now I was able to create the means with stat_summary(), but I can't figure out how to connect them while omitting my center point.

Right now I am just using geom_smooth(), which is not ideal.

p <- ggplot(data, aes(t, g_break)) + 
  geom_point() + 
  stat_summary(fun = mean) + 
  stat_summary(fun = mean, geom = "line")

Edit:

I was asked to provide some data.

structure(list(RunOrder = c(1, 2, 3, 4, 5, 6), us = c(300, 300, 
300, 160, 160, 160), t = c(200, 200, 100, 100, 200, 200), f = c(160, 
400, 400, 400, 400, 160), Blocks = c(1, 1, 1, 1, 1, 1), g_break = c(0.6, 
1, 0.4, 0, 0.1, 0.6)), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"))

Solution

  • This gives the same plot as using geom_smooth, but I'm not sure whether this is what you mean with "omitting my center point". Since it is the same as you already provided, but just omitting the first geom_summary.

    ggplot(data, aes(t, g_break)) + 
      geom_point() + 
      stat_summary(fun = mean, geom = "line")