R slopegraph geom_line color ggplot2

时间:2016-07-06 03:08:08

标签: r graph colors line

我正在尝试使用ggplotgeom_line创建一个斜率图。我希望数据子集的行(例如那些高于0.5的行)为红色,而小于0.5的行则为另一种颜色。这是我的代码:

library(ggplot2)
library(reshape2)
mydata <- read.csv("testset.csv")
mydatam = melt(mydata)

线图:

ggplot(mydatam, aes(factor(variable), value, group = Gene, label = Gene)) + 
       geom_line(col='red')

在这种情况下,所有行都是红色的。如何为那些具有可变低值的“基因”制作红线&gt; 0.5(其中有5个,aa,ac,ba,bc和bd)和其余的黑线?

mydatam看起来像这样:

   Gene variable value
1    aa  Control   0.0
2    ab  Control   0.0
3    ac  Control   0.0
4    ad  Control   0.0
5    ba  Control   0.0
6    bb  Control   0.0
7    bc  Control   0.0
8    bd  Control   0.0
9    aa      Low   0.6
10   ab      Low   0.2
11   ac      Low   0.8
12   ad      Low   0.1
13   ba      Low   0.7
14   bb      Low   0.3
15   bc      Low   0.8
16   bd      Low   1.2
17   aa     High  -0.6
18   ab     High   1.6
19   ac     High   2.1
20   ad     High   0.7
21   ba     High  -1.2
22   bb     High  -0.7
23   bc     High  -0.8
24   bd     High   0.6

1 个答案:

答案 0 :(得分:0)

您可能希望在数据中为此创建一个新变量。这是一种方式:

newval

现在我们可以使用## Color lines based on `newval` column ggplot(newdat, aes(factor(variable), value, group = Gene, label = Gene)) + geom_line(aes(color = newval)) + scale_color_manual(values = c("#000000", "#FF0000")) 创建绘图来设置颜色。

var html = document.createElement('input');
html.type = 'button';
html.id = 'testing button';
html.value = 'test';
var DOMElement = new createjs.DOMElement(html);

var target = document.getElementById(<name of a div in your HTML>);

target.appendChild(html);

//returns the first canvas element seen in the page
var canvas = document.getElementsByTagName('canvas')[0];
var stage = new createjs.Stage(canvas);

createjs.Ticker.addEventListener("tick", function(event) {
    stage.update(event);
});

stage.addChild(DOMElement);
stage.update();
相关问题