ggplot error (naming plot for ggarrange)

Hello
I have created a few plots via the code below and want to arrange them into one screen via ggarrange. I need the plots to have a name to do so, but every method I've tried has provided the below error. Any assistance would be greatly appreciated!

Error in fortify():
! data must be a data frame, or other object coercible by fortify(), not an S3 object with class uneval.
Did you accidentally pass aes() to the data argument?

PLOT 1

outcome.summary.O.R.Longer %>%
filter(Variable%in% 'Response.Time') %>%
filter(Measure%in% 'mean') %>%
RT <- ggplot(aes(x = factor(DCD.Possible.MABC),
y = Value,
fill = factor(Pre.or.Post.Stimulus))) +
ggdist::stat_halfeye(
adjust = 0.5,
justification = -.2,
.width = 0,
point_colour = NA,
alpha = 0.5
) +
geom_boxplot(
width = .12,
outlier.color = NA,
alpha = 0.5)

PLOT 2

outcome.summary.O.R.Longer %>%
filter(Variable%in% 'Step.Length.SD') %>%
filter(Measure%in% 'mean') %>%
SLV <-ggplot(aes(x = factor(DCD.Possible.MABC),
y = Value,
fill = factor(Pre.or.Post.Stimulus))) +
ggdist::stat_halfeye(
adjust = 0.5,
justification = -.2,
.width = 0,
point_colour = NA,
alpha = 0.5
) +
geom_boxplot(
width = .12,
outlier.color = NA,
alpha = 0.5)

Arrange

ggarrange(RT, SLV ),
labels = c("", "", ""),
ncol = , nrow = )

1 Like

It looks like the PLOT1 and PLOT2 sections need to be split into a data object and plot object. Then, the data object can be passed into the plot object. See update below.

# PLOT 1
df1 = outcome.summary.O.R.Longer %>%
  filter(Variable%in% 'Response.Time') %>%
  filter(Measure%in% 'mean')

RT <- ggplot(df1, aes(x = factor(DCD.Possible.MABC),
                      y = Value,
                      fill = factor(Pre.or.Post.Stimulus))) +
  ggdist::stat_halfeye(
    adjust = 0.5,
    justification = -.2,
    .width = 0,
    point_colour = NA,
    alpha = 0.5
  ) +
  geom_boxplot(
    width = .12,
    outlier.color = NA,
    alpha = 0.5)

# PLOT 2
df2 = outcome.summary.O.R.Longer %>%
  filter(Variable%in% 'Step.Length.SD') %>%
  filter(Measure%in% 'mean') 

SLV <-ggplot(df2, aes(x = factor(DCD.Possible.MABC),
                      y = Value,
                      fill = factor(Pre.or.Post.Stimulus))) +
  ggdist::stat_halfeye(
    adjust = 0.5,
    justification = -.2,
    .width = 0,
    point_colour = NA,
    alpha = 0.5
  ) +
  geom_boxplot(
    width = .12,
    outlier.color = NA,
    alpha = 0.5)
1 Like

Thank you for your assistance!
I have this working in a multi-plot visual now!

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.