我看起來像這樣的一個數據幀:着色與scale_color_manual
d= data.frame(Name = c("B","A","A","B","A","B"),
Group= c("one","one","two","two","three","three"),
value=c(.5,.6,.7,.8,.4,.2))
d
Name Group value
1 B one 0.5
2 A one 0.6
3 A two 0.7
4 B two 0.8
5 A three 0.4
6 B three 0.2
當我繪製它看起來是這樣的。注意到,其中A線是
ggplot(d,
aes(x=factor(Group),
y= value,
group= Name , color =Name)) +
geom_point()+geom_line()
現在我想用刻度顏色手冊這樣來着色行:
library(RColorBrewer)
n <- 60
qual_col_pals = brewer.pal.info[brewer.pal.info$category == 'qual',]
col_vector = unlist(mapply(brewer.pal, qual_col_pals$maxcolors, rownames(qual_col_pals)))
ggplot(d,
aes(x=factor(Group),
y= value,
group= Name , color =Name)) +
geom_point()+geom_line() +
scale_color_manual(name="name",
labels = unique(d$Name)
,
values= col_vector[14:(14+(length(unique(d$Name)))-1)]
)
產生這個圖像,其中「A」行是不正確。現在是「B」線。我如何縮放顏色手冊以使用col_vector中的顏色更改輸出,但保留正確的輸出?在訂單