I'm currently trying to recreate an estimated marginal means plot I created using the stats software Jamovi. Jamovi uses ggplot2 to create all its graphs and it spit out this one for me:
The problem is that the journal I'm trying to submit my manuscript to does not publish colored images and I will need to recreate the graphs in black and white (jamovi offers a grey color palette but it's hard to differentiate between the greys).
I managed to use ggplot2 in R to recreate this so far
with the following code:
ggplot(data, aes(x = xvar, y = yvar)) +
geom_line(aes(linetype = class), size = 1, show.legend = FALSE) +
facet_grid() +
geom_point(aes(shape = class), size = 2.5) +
theme(axis.text = element_text(size = 16, colour = "black"), axis.title = element_text(size=16),
title = element_text(size = 14), legend.text = element_text(size = 14)) +
labs(x = "", y = "", title = "") +
xlim(c(2,4)) + ylim(c(0,1)) +
stat_smooth(aes(x = xvar, y = yvar), method="lm", formula = y ~ x, se = FALSE, fullrange = TRUE)
I'm trying to smooth out the lines between the data points like in the first graph and also have the lines extend out beyond the current range it has (2.70 - 3.7) but I don't know how to do it in ggplot. It shouldn't be a data issue because I created the data using the data frame that jamovi's own R package gave me (which is the same data frame it uses to create its plots in ggplot).
I tried following the directions listed in this question but it only gives me that blue line you see in the second graph when I use stat_smooth
. When I tried to follow the instructions precisely and used this code:
ggplot(data) +
geom_plot(aes(x = xvar, y = yvar), size = 2) +
stat_smooth(aes(x = xvar, y = yvar), method = "lm", formula = y ~ poly(x, 2), se = FALSE) +
coord_cartesian(ylim = c(0,1))
I instead got the following error message:
Error in geom_plot(aes(x = xvar, y = yvar), size = 2) :
could not find function "geom_plot"
My three questions are thus as follows:
1) How do I smooth out the lines between the data points?
2) How do I extend the lines out to the edge of the x-axes (from say, 1 to 5) like in the first graph?
3) Is there a way to anti-alias the lines like in the first graph?
Here's some sample data (not the data I used to create the plots but similar in the same format as what was given to me by jamovi where "class" is the grouping variable),
xvar class yvar
2 1 0.25
2 2 0.3
2 3 0.2
2 4 0.13
3 1 0.15
3 2 0.35
3 3 0.18
3 4 0.24
4 1 0.1
4 2 0.45
4 3 0.14
4 4 0.27