当用ggplot(geom_line)在一个图上绘制2条线时,该线的颜色不等于我设置的颜色。我想要黑色和蓝色线条,但结果是红色和蓝色。我在没有(第一个代码)和(第二个)'scale_color_manual'的情况下进行了尝试,还尝试了使用颜色插入颜色,结果相同:
第一个代码:
ggplot(data=main_data) +
# black plot
geom_line(aes(x=vectors_growth_rate_with_predator,
y=disease_prevalnce_with_predator,
color = "black")) +
# blue plot
geom_line(aes(x=vectors_growth_rate_with_predator,
y=disease_prevalnce_without_predator,
color = "blue"))
Run Code Online (Sandbox Code Playgroud)
第二个代码:
PrevVSGrowth =
ggplot(data=main_data) +
# black plot
geom_line(aes(x=vectors_growth_rate_with_predator,
y=disease_prevalnce_with_predator)) +
# blue plot
geom_line(aes(x=vectors_growth_rate_with_predator,
y=disease_prevalnce_without_predator))
PrevVSGrowth + scale_color_manual(values=c(disease_prevalnce_with_predator= 'black',
disease_prevalnce_without_predator = 'blue'))
Run Code Online (Sandbox Code Playgroud)