Search code examples
rbubble-chartmetafor

Change bubble color using regplot


I have conducted a meta-regression in R using metafor package.

res.quad <- rma(mix.minor.1.1_estimates, sei = mix.minor.1.1_errors, mods = ~ poly(minperc, degree=2, raw=TRUE), data=meta2)
res.quad

Then, I build a bubble plot

xs <- seq(0, 1, length=10)
sav <- predict(res.quad, newmods=unname(poly(xs, degree=2, raw=TRUE)))
regplot(res.quad, mod=2, pred=sav, xvals=xs, xlab="Proportion of ethnic minority in class", ylab="Ethnic minority homophily")

However, I want to change the color of bubbles according to the city variable. I do not use it in meta-regresssion, but it exists in meta2 dataframe which I use. Is there any way to do what I need?

Thanks)

meta2 <- data.frame(mix.minor.1.1_estimates = c(1, -1, 2, 2.3, 4.2, 0, -3.5),
                 mix.minor.1.1_errors = c(0.1, 0.5, 0.3, 0.3, 0.2, 0.1, 0.5),
city = c("n", "s", "n", "s", "n", "s", "n"),
minperc = c(0.8, 0.9, 0.1, 0.6, 0.3, 0.2, 0.5))

Solution

  • The bg and col arguments allow you to adjust the (background) color of the points and also accept vectors as arguments. See the docs. For example:

    regplot(res.quad, mod=2, pred=sav, xvals=xs, 
            xlab="Proportion of ethnic minority in class", 
            ylab="Ethnic minority homophily", 
            bg=ifelse(meta2$city == "n", "firebrick", "dodgerblue"))