Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plot list structure in R

I work more and more with highly nested lists such as:

mynestedlist<-list(list(LETTERS,month.name),list(list(seq(1,100,5),1,1),seq(1,100,5),seq(1,100,5)))

and sometimes I struggle to understand the structure of the list I am working on. I was wondering if there is any way to display the hierarchical structure of a list, using dendrogram-like graphs maybe.

I know I can use str to print the structure of a list:

str(mynestedlist,max.level=1)

However, a graphical way to display lists would be more useful!

like image 722
matmar Avatar asked May 16 '16 21:05

matmar


People also ask

Can you plot a list in R?

Two-dimensional list can be created in R programming by creating more lists in a list or simply, we can say nested lists. The list() function in R programming is used to create a list. In this article, we'll learn to create plot graph using Two Dimensional List in R programming.

How do I create a list in R?

How to Create Lists in R? We can use the list() function to create a list. Another way to create a list is to use the c() function. The c() function coerces elements into the same type, so, if there is a list amongst the elements, then all elements are turned into components of a list.

What is the syntax for the list in R?

Data Visualization using R Programming Lists are the R objects which contain elements of different types like − numbers, strings, vectors and another list inside it. A list can also contain a matrix or a function as its elements. List is created using list() function.


1 Answers

You may check the data.tree package. It allows to print nested list pretty nicely and it doesn't need you to write complicated function. Here is an example:

library(data.tree)
> dt <- FromListSimple(mynestedlist)
> dt
  levelName
1 Root     
2  ¦--1    
3  °--2    
4      °--1

This allows you to check at the level of list, and you can combine this with str to get a full picture of your list structure.

like image 178
Psidom Avatar answered Oct 22 '22 21:10

Psidom