keep row names with melt

4,538 views
Skip to first unread message

Zev

unread,
Jul 5, 2011, 10:51:24 PM7/5/11
to ggplot2
the data:

dataframe(data)

group1 group2
NA18909 0.00001 0.99999
NA06985 0.99999 0.00001
NA18593 0.00001 0.99999
NA18505 0.00001 0.99999


hopeful melt:


NA18909 0.00001 group1
NA06985 0.99999 group1
NA18593 0.00001 group1
NA18505 0.00001 group1
NA18909 0.99999 group2
NA06985 0.00001 group2
NA18593 0.99999 group2
NA18505 0.99999 group2

Snippet of what i get when I melt dataframe(data):

74 group2 0.000010 1
75 group2 0.000010 1

How can I achieve the desired melt?

Ista Zahn

unread,
Jul 5, 2011, 11:12:25 PM7/5/11
to Zev, ggplot2
data.frame rownames must be unique. If you want to use the rownams, convert them into a column in the data.frame before melting.

Best,
Ista


--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2



--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

Ito, Kaori (New London/PGRD)

unread,
Jul 6, 2011, 11:33:27 AM7/6/11
to Ista Zahn, Zev, ggplot2

Is this what you want? You can also use any name instead of “id”.

 

d <- data.frame(id=c("NA18909","NA06985","NA18593","NA18505")

                     ,group1=c(0.00001,0.99999,0.00001,0.00001)

                     ,group2=c(0.99999,0.00001,0.99999,0.99999)

                     )

> d

       id  group1  group2

1 NA18909 0.00001 0.99999

2 NA06985 0.99999 0.00001

3 NA18593 0.00001 0.99999

4 NA18505 0.00001 0.99999

 

> melt(d, measure.var=c("group1","group2"))

       id variable   value

1 NA18909   group1 0.00001

2 NA06985   group1 0.99999

3 NA18593   group1 0.00001

4 NA18505   group1 0.00001

5 NA18909   group2 0.99999

6 NA06985   group2 0.00001

7 NA18593   group2 0.99999

8 NA18505   group2 0.99999

 

Kaori Ito

Pfizer Inc

Groton, CT USA


Zev

unread,
Jul 6, 2011, 11:36:03 AM7/6/11
to ggplot2
Yes and Yes. I was just beating my head against the wall trying to
find a row names option.
Thanks for both of your help.



On Jul 6, 9:33 am, "Ito, Kaori (New London/PGRD)"
> <mailto:ggplot2%2Bunsu...@googlegroups.com>
> More options:http://groups.google.com/group/ggplot2
>
> --
> Ista Zahn
> Graduate student
> University of Rochester
> Department of Clinical and Social Psychologyhttp://yourpsyche.org
Reply all
Reply to author
Forward
0 new messages