2012-05-01 124 views
2

我試圖如何更改ggplot2中的軸標籤顏色?

... + xlab("New label", colour="darkgrey") 

... + xlab("New label", color="darkgrey") 

但它說,這種說法是不使用的。我查看?xlab,但它不包含任何顏色參數。有沒有可能改變它?怎麼樣?

回答

13

試試這個,使用opts

dat <- data.frame(x = 1:5,y = 1:5) 
p <- ggplot(dat,aes(x,y)) + geom_point() 
p + opts(axis.title.x = theme_text(colour = "red"), 
     axis.title.y = theme_text(colour = "blue")) 

This頁是學習所有的選項一個很好的起點。

自從發佈ggplot2 0.9.2 opts已被棄用。當前版本的語法將更多的東西是這樣的:

p + theme(axis.title.x = element_text(colour = "red"), 
      axis.title.y = element_text(colour = "blue")) 

存在用於更新你的代碼的詳細transition guide

+5

新語法:p + theme(axis.title.x = element_text(color =「red」), + axis.title.y = element_text(color =「blue」)) – PatrickT

+0

@PatrickT謝謝!我應該更好地更新我的答案,但是那一天只有很多時間。今後,請隨意直接提供對我的答案的編輯,並使用更新的語法,我會收到通知並可以直接批准。 – joran

相關問題