2017-03-16 48 views
0

我要創建我的曼哈頓陰謀使用這種編程:GGPLOT2 - R:把不同的顏色對我集團在曼哈頓情節

ggplot(subset(data1), aes(CHR, P),group=CHR) + 
geom_point(pos = position_jitter(w = 0.45, h = 0.45), 
aes(colour =(CHR)))+ 
scale_x_discrete(limits=c(1:27)) + 
theme(legend.position="none")+ ylab("Bayes Factor") + 
geom_hline(yintercept=20,colour="red", alpha=I(1/3)) + 
geom_hline(yintercept=150,colour="red", alpha=I(3/3)) 

但是,在這種情況下,每個組(如CHR)有藍色的水平。 但我希望每個組(每個CHR - 27)都有一種顏色。

我嘗試了一些功能,但並沒有改變顏色:

+ scale_fill_manual(name = "Values", values=setNames(colors, 1:8)) 

+ scale_fill_brewer(palette = "Set1") 

+ scale_colour_brewer(palette = "Set1") 

 + scale_colour_brewer(breaks=c("1","2","3","4","5","6","7","8","9","10","11", 
    "12","13","14","15","16","17","18","19","20","21","22","23","24","25","26", 
    "27"), palette = "Set1") 

+ d+scale_colour_brewer(breaks=c("1","2","3","4","5","6","7","8","9","10","11", 
"12","13","14","15","16","17","18","19","20","21","22","23","24","25","26", 
values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", 
"#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00","#E69F00", 
"#56B4E9", "#009E73", 
"#F0E442", "#0072B2", "#D55E00","#E69F00", "#56B4E9", "#009E73", 
"#F0E442", "#0072B2", "#D55E00","#E69F00", "#56B4E9", "#009E73")) 
+0

也許嘗試把'組= CHR'內'AES(...)在第一線'這樣記載:'ggplot(子集(數據1),AES(CHR ,P,group = CHR))+' – sinQueso

+1

會更容易回答是你提供了足夠的數據(使用'dput')使你的問題可以重現 –

+0

@sinQueso我試過了,但是隻有這個沒有改變。正如馮的回答,這個問題是列分類。但是,謝謝。 –

回答

0

它無關,與你的調色板選擇。這是因爲CHR列是數字,而不是一個因素。您需要先將其轉換:

data1$CHR <- as.factor(data1$CHR) 

ggplot(subset(data1), aes(CHR, P, group = CHR)) + 
geom_point(pos = position_jitter(w = 0.45, h = 0.45), 
aes(colour =(CHR))) 
+0

謝謝。但我可以在這裏更改托盤顏色?對我來說是「柔和的色彩」,我想要「熱色」。我可以做這個? @馮 –

+0

當然。現在您可以使用'scale_color_manual'或任何調色板功能的調製器,因爲您試圖選擇任何您喜歡的顏色。 – Feng