【发布时间】: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$。这不是必需的,并且可能会导致令人惊讶的结果。