【问题标题】:Fixing Error: Insufficient values in manual scale. 2 needed but only 1 provided. In R修复错误:手动比例中的值不足。需要 2 个,但只提供了 1 个。在 R 中
【发布时间】:2020-10-13 18:45:26
【问题描述】:

我会创建这样的图表enter image description here

但我遇到了问题:错误:手动刻度中的值不足。需要 2 个,但只提供了 1 个

这是我的代码

Library(ggplot2)

Library(read_xl)

df2 <- read_excel("Data122.xlsx", sheet = "sheet4")

ggplot(Data=df2) + 
  geom_line(aes(col="COP", 
                x =df2$`Ground Temp T1 Tg`, 
                y=df2$`Daily COP`), size= 2) + 
  theme_bw() + 
  labs(x = "Entering source temperature EST", y = "COP") + 
  geom_point() + theme(legend.position = "top") + 
  scale_color_manual(values=c("#FF3333")) + 
  theme(legend.title = element_blank()) + 
  scale_y_continuous(name = "COP", 
                     sec.axis = sec_axis(trans = ~ . *1, 
                                         name = "Produced and Consumed power MWh")) + 
  geom_line(aes(col = "Consumed Power", 
                x = df2$`Ground Temp T1 Tg`, 
                y = df2$`Electricity MWh day`), size= 2)
**Insufficient values in manual scale. 2 needed but only 1 provided**

【问题讨论】:

  • 好吧,您需要在scale_color_manual 中提供第二种颜色。另外,从aes 内部删除df2$。这不是必需的,并且可能会导致令人惊讶的结果。

标签: r ggplot2


【解决方案1】:

我需要你的数据样本来确定,但你的问题在scale_color_manual()。您提供了一个颜色值来映射到数据,但数据中必须有两个值才能映射。如果您希望所有东西都是那种颜色,请不要将颜色映射为美学,只需将其作为参数提供:

 geom_line(aes(x =df2$`Ground Temp T1 Tg`, 
               y=df2$`Daily COP`), size = 2, color = "#FF3333")

以下是有关您的代码的其他一些提示。在您的aes() 映射中,您有df2$。你不需要那个。在原来的ggplot() 调用中提供data = 的全部原因是为了避免这种情况。

 geom_line(aes(x = `Ground Temp T1 Tg`, 
               y = `Daily COP`), size = 2, color = "#FF3333")

您的geom_point() 图层没有美学映射,ggplot() 调用中也没有任何定义。图层不会从其他图层继承美学。你的情节不会有任何积分。

【讨论】:

    猜你喜欢
    • 2019-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    • 2018-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多