2

I am creating interaction plots in ggplot2 and keep coming up with the following error: Error: Insufficient values in manual scale. 4 needed but only 2 provided.

Code:

    plot1<- data.frame(effect("current*child", outcome, 
    xlevels=list(child=c(-1,1))))
    ggplot(plot1) + geom_line(aes(current, fit,  color = child, 
    linetype=factor(current)), size= 1.25, )+ scale_colour_gradient(low = 
    "darkred", high = "darkblue") + theme_bw()+
    coord_cartesian(xlim=c(-10,10), ylim=c(-10,10)) +
    scale_linetype_manual(values=c("solid", "dotted"))+
    theme(legend.position='none', panel.grid.major = element_blank(),
        text = element_text(size=16),
        panel.grid.minor = element_blank(),)+ 
    xlab("Current")+ylab("Outcome") 

I believe it has something to do with scale_color_gradient(low = "darkred", high = "darkblue"). However, I don't know how to alter this to remove the error for an interaction plot.

Thanks!

lovalery
  • 4,524
  • 3
  • 14
  • 28
R Forbes
  • 21
  • 2
  • 1
    please provide a reproducible example with the dput output of your data frame – Robin Gertenbach Apr 27 '17 at 20:13
  • 3
    It's more likely to do with `scale_linetype_manual(values=c("solid", "dotted"))`. But when asking for plotting help especially, you need to include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data so we can run the code to see what's going on. – MrFlick Apr 27 '17 at 21:06

0 Answers0