我已經
我想根據它們在資料框中的方式更改圖例標簽,使它們分別為 A、B、C 和 D。我該怎么做呢?
uj5u.com熱心網友回復:
您仍在按照在基礎繪圖中的方式設定資料。您的 data.frame 應該只具有您想要為其設定顏色的因素,并且已經存在正確的級別。然后使用 ascale更改調色板,與資料本身分開。
這是ggplot方法:
library(ggplot2)
set.seed(30)
df <- data.frame(
x = runif(5000),
y = runif(5000),
color = sample(x = c('A', 'B', 'C', 'D'),
size = 5000,
replace = TRUE)
)
my_colors <- c(A = "#E41A1C", B = "#377EB8", C = "#4DAF4A", D = "#984EA3")
ggplot(df, aes(x = x, y = y, color = color))
geom_point()
scale_color_manual(values = my_colors)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/493106.html
下一篇:無法更改ggplot中的ylab
