I try to customize the multiline graphs from the effects package.
Is there anyway to position the legend in the example below within the plotting area and not above the graph?
Alternatively: Does anyone know how to plot the results of the multiline regressions calculated by the effects package using ggplot2?
I appreciate any help.
Andy
Example:
library(effects)
data(Prestige)
mod5 <- lm(prestige ~ income*type + education, data=Prestige)
eff_cf <- effect("income*type", mod5)
print(plot(eff_cf, multiline=TRUE))
This is how you plot effect object in ggplot
library(ggplot2)
## Change effect object to dataframe
eff_df <- data.frame(eff_cf)
## Plot ggplot with legend on the bottom
ggplot(eff_df)+geom_line(aes(income,fit,linetype=type))+theme_bw()+
xlab("Income")+ylab("Prestige")+coord_cartesian(xlim=c(0,25000),ylim=c(30,110))+
theme(legend.position="bottom")
You can change xlim
and ylim
depending on how you want to display your data.
The output is as follows:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With