2015-01-07 117 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'的值是什么。 –