0

我正在尝试使用 multiplot 绘制图表,我不太了解我的功能。我想针对时间跨度设置不同的颜色,针对所使用的回归类型设置不同的形状。我尝试使用 ggplot 设置:我在 multiplot 函数中设置颜色和形状的级别,然后添加 scale_shape_manual 来设置颜色和形状,但它似乎不起作用。我将非常感谢您的帮助。

这是我正在运行的代码:

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"))

我收到以下错误消息:“'颜色'的比例已经存在。为'颜色'添加另一个比例,它将替换现有的比例。'形状'的比例已经存在。为'形状'添加另一个比例,这将替换现有的刻度。错误:手动刻度中的值不足。需要 24,但只提供了 8。

4

0 回答 0