0

I have two models showing the effect of different Treatments (A, B, C) on animal diversity in a large plot (Model 1), and in a small plot (Model 2). In Model 1, I included all three Treatments in the model, but in Model 2, Treatment C had to be removed. When I plot the model outputs (in ggplot2), the plot for Model 1 shows Treatments A, B, C on the x axis, but Model 2 of course only shows Treatments A and B on the x axis.

I would like my x-axis to show Treatment A, B, C for both models. How do I add a 'dummy' factor into the plot of Model 2, to ensure that Treatment A and B line up between the two plots (plotted on top of each other).

[See picture for clarification here][1]

Thank you in advance. [1]: https://i.stack.imgur.com/8WiXZ.png

AMK
  • 1
  • 1
  • Hi AMK, can you provide a reprex? (see: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Marcelo Avila Mar 25 '21 at 15:17

1 Answers1

0

One solution is to use facet function. But for me, this was not an option, so I have now added factor level "C" to my dataframe used for plotting Model 2.

df[nrow(df)+1,] <- NA # add additional row df$x <- as.character(df$x) <- make the factor column as.character, because else you get an error with the below. df$x[is.na(df$x)] <- "C" # give your new factor level a name; all other cells in the row can remain NAs df$x <- as.factor(df$x) # convert the factor column back to as.factor

now we can plot it.

AMK
  • 1
  • 1