我正在嘗試更改此圖上單個“年”變數的顏色。到目前為止,我有這個代碼:
x <- ggplot(elect, aes(x = `Congressional Spending`, y = `United States VEP Midterm Turnout Rate`, color = Year))
geom_point() geom_smooth(method = lm, col = 'purple', size = 0.5)

我也嘗試過使用:
scale_color_manual(values = c("red", "yellow",
"blue", "orange",
"green", "black"))
錯誤:提供給離散刻度的連續值
uj5u.com熱心網友回復:
看看資料會很有幫助。問題很可能是您的變數year是double. 所以你需要呼叫as.factor()你的代碼(見下文):
library(tidyverse)
ggplot(mtcars, aes(x=gear, y=carb, color=as.factor(cyl)))
geom_point()
scale_color_manual(values = c("black","green","blue"))

由reprex 包(v2.0.0)于 2022-04-27 創建
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/466712.html
