2016-02-29 34 views
1

这里是我的代码设置barplot颜色,并添加x轴值

#!/usr/bin/R 

c1 <-c(60,199,102,134,81,95,135,151,102,112,211,120) 
barplot(c1, main="number of points per cluster", 
    color="dark blue") 

但警告消息称

警告信息:1:在plot.window(XLIM,ylim,登录=日志,...):
“色” 是不是一个图形化的参数

我的形象enter image description here

我也想在x轴上从1到12的数字。

+0

山坳= C(“深蓝”) – HubertL

回答

5

要设置颜色使用col,而不是color。要在x轴上有数字,我们可以指定名称c1

c1 <- c(60,199,102,134,81,95,135,151,102,112,211,120) 
names(c1) <- 1:length(c1) 

barplot(c1, main = "number of points per cluster", 
     col = "dark blue") 

enter image description here

+0

所有空白在颜色名称剥夺你只是吹我的脑海 – rawr

+0

@rawr嘿,其实你吹我的脑海里,我还没有检查有空格的颜色名称。 – zx8754

0

要添加到对方的回答:你也可以甚至更进一步的分类数据和匹配的颜色数据本身。

c1 = c(60,199,102,134,81,95,135,151,102,112,211,120) 
names(c1) = LETTERS[1:length(c1)] # random data labels from alphabet 
barplot(sort(c1, decreasing=T), 
     main="Barplot with Data-Based Colors", 
     col=heat.colors(length(c1))) 

enter image description here