0

I am trying to plot a graph using multiplot, I function that I do not know really well. I want to set different colours with respect to the time span and different shapes with respect to the type of regression used. I tried to use the ggplot settings: I set the levels for colour and shape inside the multiplot function and then I add scale_shape_manual to set colours and shapes, but It does not seem to work. I will really appreciate your help.

Here the code I am running:

Model <- factor(c("Without controls","With controls 1","With controls 2",
           "Without controls","With controls 1","With controls 2",
           "Without controls","With controls 1","With controls 2",
           "Without controls","With controls 1","With controls 2",
           "Without controls","With controls 1","With controls 2",
           "Without controls","With controls 1","With controls 2",
           "Without controls","With controls 1","With controls 2",
           "Without controls","With controls 1","With controls 2"),
           levels = c("Without controls","With controls 1","With controls 2"))

Time_span <- factor(c("Day+0","Day+0","Day+0",
               "Day+3","Day+3","Day+3",
               "Day+7","Day+7","Day+7",
               "Day+14","Day+14","Day+14",
               "Day+21","Day+21","Day+21",
               "Day+30","Day+30","Day+30",
               "Day+60","Day+60","Day+60",
               "Day+90","Day+90","Day+90"),
               levels = c("Day+0","Day+3","Day+7","Day+14","Day+21","Day+30","Day+60","Day+90"))

coefplot::multiplot(string0,string01,string02,
                          string1,string11,string12,
                          string2,string21,string22,
                          string3,string31,string32,
                          string4,string41,string42,
                          string5,string51,string52,
                          string6,string61,string62,
                          string7,string71,string72,
  intercept = FALSE, #if display the intercept
                     numberAngle=0, #The angle for the value labels, 0 is horizontal
                     coefficients = "wvs_risk", #coeff to show 
                     title= NULL,
                     ylab = NULL,
                     xlab = "Stringency",
                     zeroColor = "black", #The color of the line indicating 0
                     zeroLWD = 1, #The thickness of the 0 line
                     zeroType = 1, #The type of 0 line, 0 will mean no line
                     color = Time_span,
                     shape = Model) +
  coord_flip()+
  theme_light() +
  theme(legend.position = "left") +
  scale_colour_manual(values = c("#e49205","#a15439","#e11e47","#e72eb6","#2b63e1",
                                 "#32cdaf","#74bb81","#93e424"),
                      labels = c("Day+0","Day+3","Day+7","Day+14","Day+21","Day+30","Day+60","Day+90"),
                      name = "Time span") +
  scale_shape_manual(values = c(0,16,25),
                     labels = c("Without controls","With controls 1","With controls 2"),
                     name = "Model") +
  guides(colour = guide_legend(order = 2), shape = guide_legend(order = 1)) + 
  scale_y_discrete(labels=c("Risk taking"))

I get the following error message: "Scale for 'colour' is already present. Adding another scale for 'colour', which will replace the existing scale. Scale for 'shape' is already present. Adding another scale for 'shape', which will replace the existing scale. Error: Insufficient values in manual scale. 24 needed but only 8 provided."

  • 1
    Hi Martina! Welcome :) Could you specify the problem you are having with your code? Ideally please include any error output you are getting, as text, by editing your Question. This will help users to solve your problem. – tjheslin1 Oct 20 '21 at 10:06
  • Yes, thank you! I include the error text message. – Martina Dattilo Oct 20 '21 at 14:29

0 Answers0