使用行名

时间:2015-08-13 03:01:39

标签: r ggplot2 reshape

我有数据框,我想将前两列行+变量名称传递给图例。

df内部我有一组数据集,其中包含从ah的字母。

我想要成功的是78_256_DQ0_a78_256_DQ1_a之类的东西 对于其他群组,78_256_DQ2_aa传说ggplot等等。 我不知道如何将此格式传递给df <- do.call(rbind,lapply(1,function(x){ AC <- as.character(rep(rep(c(78,110),each=10),times=3)) AR <- as.character(rep(rep(c(256,320,384),each=20),times=1)) state <- rep(rep(c("Group 1","Group 2"),each=5),times=6) V <- rep(c(seq(2,40,length.out=5),seq(-2,-40,length.out=5)),times=2) DQ0 = sort(replicate(6, runif(10,0.001:1))) DQ1 = sort(replicate(6, runif(10,0.001:1))) DQ2 = sort(replicate(6, runif(10,0.001:1))) No = c(replicate(1,rep(letters[1:6],each=10))) data.frame(AC,AR,V,DQ0,DQ1,DQ2,No) })) 。 任何帮助将不胜感激。

假设我有这样的数据框;

    AC  AR     V         DQ0        DQ1        DQ2 No
1   78 256   2.0 0.003944916 0.00902776 0.00228837  a
2   78 256  11.5 0.006629239 0.01739512 0.01649540  a
3   78 256  21.0 0.048515226 0.02034436 0.04525160  a
4   78 256  30.5 0.079483625 0.04346118 0.04778420  a
5   78 256  40.0 0.099462310 0.04430493 0.05086738  a
6   78 256  -2.0 0.103686255 0.04440260 0.09931459  a
*****************************************************
  

头(DF)

df

此代码用于绘制library(reshape2) df_new <- melt(df,id=c("V","No"),measure=c("DQ0","DQ1","DQ2")) library(ggplot2) ggplot(df_new,aes(y=value,x=V,group=No,colour=No))+ geom_point()+ geom_line()

using System;
using System.Collections.Generic;

public class TestObject
{
    private TestObjectCollection _testObjects;

    public string name { get; set; }
    public TestObjectCollection parentCollection { get; set; }
    public TestObjectCollection testObjects 
    { 
        get
        {
            return _testObjects;
        }
        set 
        {
            _testObjects = value;
            _testObjects.parent = this;
        }
    }
}

public class TestObjectCollection
{
    private List<TestObject> _testObjects;

    public TestObject parent { get; set; }

    public TestObjectCollection()
    {
        _testObjects = new List<TestObject>();
    }

    public void Add(TestObject testObject)
    {
        testObject.parentCollection = this;
        _testObjects.Add(testObject);
    }

    public TestObject this[int i] {
        get {
            return _testObjects[i];
        }
    }
}


public class Test
{
    public static void Main()
    {
        // your code goes here
        TestObject test1 = new TestObject();

        TestObject test2 = new TestObject();

        var collection = new TestObjectCollection();
        collection.Add(test2);
        test1.testObjects = collection;

        if (test2.parentCollection.parent == test1)
        {
            Console.WriteLine("Done");
        }
        else
        {
            Console.WriteLine("Fail");
        }
    }
}

enter image description here

1 个答案:

答案 0 :(得分:2)

为你的美学添加lty = variable,如下:

ggplot(df_new, aes(y = value, x = V, lty = variable, colour = No)) +
  geom_point() +
  geom_line()

会为DQ0DQ1DQ2提供单独的行。

enter image description here