strengejacke / ggeffects

Estimated Marginal Means and Marginal Effects from Regression Models for ggplot2
https://strengejacke.github.io/ggeffects
Other
565 stars 36 forks source link

Control color based on group in a clm() or cumulative model when using plot() #560

Open mz555 opened 3 months ago

mz555 commented 3 months ago

I am attempting to change the colours of the estimates in my plot based on the levels of Condition, but the "color = " element in plot() doesn't recognise the grouping. I have tried other solutions from the other issues posted here but nothing works:

Example code:

library(ordinal)
ancova.suit = clm(SuitAfter ~ Condition + SuitB4,
                  data = Historicaldata,
                  link = "cauchit")

library(ggeffects)
plot.suit <- ggeffects::ggpredict(ancova.suit, c("Condition"))
plot(plot.suit, colors = c("blue", "pink"), n_rows = 1, facet = TRUE, show_legend = TRUE)

This produces this: image

All I want is for the levels ("2" and "3") of Condition to be in different colours. Is there a way to do this?

Things I've tried:

p <- plot(plot.suit, n_rows = 1,) +
  scale_color_manual(values = c("black", "red"), labels = c("2", "3")) +
  labs(color = "Condition")

Which gives this error:

Scale for colour is already present.
Adding another scale for colour, which will replace the existing scale.
strengejacke commented 2 months ago

Do you have a reproducible example?