2015-01-07 120 views
0

我試圖爲函數的圖形繪製設置默認參數。但是,每當我將向量分配給col時,我都會收到錯誤graphical parameter "col" has the wrong length在R中設置默認繪圖值

我試圖代碼:

par(col=c("#000", "#ccc"), font.lab=2, col.axis="#404040") 

,我希望輸出柱狀圖有黑色和淺灰色,其軸標籤以粗體和深灰色的顏色。

例如,以下代碼(從下面的lukeA借用)生成灰度示例,而不是顏色。字體也不是粗體。

par(font.lab=2, fg="#404040", bg="#ffffff") 
# Defining palette plot colours = NOT gray scale 
palette(c("paleturquoise3", "palegreen3")) 

set.seed(1) 

tRegion <- table(Region = sample(1:3, size = 50, replace = TRUE), 
       Variant = sample(LETTERS[1:2], size = 50, replace = TRUE)) 

barplot(t(tRegion), main="Distribution of variant and region", 
     xlab="Region", legend = rownames(t(tRegion))) 

輸出如下:

enter image description here

否粗體,並且沒有顏色。

+0

請提供(1)最小和(2)重複的例子,和(3)解釋,究竟是不是應該如此。 – lukeA

+0

@lukeA看我的編輯。 –

+0

我的錯:將'col = seq_len(ncol(tRegion))'添加到'barplot'。粗體字體在這裏工作(Windows 7)。 – lukeA

回答

0

試試這個

par(font.lab=2, col.axis="#404040") 
palette(c("#000000", "#cccccc")) 
barplot(1:2, col = 1:2, names.arg = 1:2, xlab = "1", ylab = "2") 

編輯:

至於您的評論 - 爲我工作:

par(font.lab=2, col.axis="#404040") 
palette(c("paleturquoise3", "palegreen3")) 
set.seed(1) 
tRegion <- table(Region = sample(1:3, size = 50, replace = TRUE), 
       Variant = sample(LETTERS[1:2], size = 50, replace = TRUE)) 
barplot(t(tRegion), main="Distribution of variant and region",beside = TRUE, 
     col = seq_len(ncol(tRegion)), xlab="Region", legend = rownames(t(tRegion))) 
+0

最後一行是做什麼的? barplot()函數? –

+0

它繪製了一個黑色和淺灰色的條形圖,其軸標以粗體和深灰色。 – lukeA

+0

我知道那一部分,但對我的情況是否有必要?還是僅僅是一個例子?如果它不是一個例子,我不明白'1'和'2'的值是什麼。 –