如何用不同的颜色代码制作组条形图?

时间:2016-02-29 19:32:48

标签: r rscript

我正在尝试使用以下格式化数据制作分组条形图。我写了下面的代码,但它不符合我的目的

数据

data1 <- read.table(text="              NAS  AG   PT      ST
1kb_+/-TSS   1239 885   1232    952
1.5kb_+/-TSS 1440 1092  1467    1181
2kb_+/-TSS   1647 1248  1635    1398
2.5kb_+/-TSS 1839 1403  1794    1594", header=TRUE)

代码

data2=as.matrix(data1)
b<-barplot(data2, legend= rownames(data2), beside= TRUE,las=2,cex.axis=0.7,cex.names=0.7,ylim=c(0,3000), col=c("cornflowerblue","cornsilk4","red","orange"))
tx2 <- data2
text(b,tx2+10, as.character(tx2),pos = 3, cex = 0.5, col = "darkgreen")

下面是图片 enter image description here

我不希望像这样的颜色组合我想要每个组的颜色,如NAS(每行的蓝色阴影),AG(cornsilk4的阴影,PT(读取的阴影),ST(橙色的阴影) )

我该如何修改代码?所以每个类别都有我在主代码中使用的4种颜色的浅色调

1 个答案:

答案 0 :(得分:2)

如果您想为每种颜色设置不同的色调,则必须自己创建这些颜色。这是一个可以计算较浅颜色的功能

var myApp = angular.module('myApp', []);

myApp.factory('counter', function() {
    return {
        count: 0
    };
});

myApp.controller('CounterController', function (counter) {
    var vm = this;

    vm.counter = counter;
    vm.increment = function() {
        vm.counter.count = vm.counter.count + 1;
    };
});

这导致

enter image description here

基本上,我们的想法是为每种颜色添加一定量的白色(RGB刻度)。当然有更复杂的方法来选择颜色。