Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate a visual representation from a table with relation weight

I have a table in the following format:

Item A | Item B | Weight
   X   |   Y    |   2
   X   |   Z    |   5
   Y   |   Z    |   3
   Y   |   W    |   2
  ...  |  ...   |  ...

I want to generate some graph where each letter(W,X,Y,Z) is a node and have a link with some width according to the weight to the Item B.

The question is what I can use to generate this graph? Can be a tool, a Java or R library or another language. The way doesn't matter, I only need to generate the graph.

like image 515
Renato Dinhani Avatar asked Feb 21 '12 17:02

Renato Dinhani


People also ask

What is a visual representation of a data table?

Data visualization is the graphical representation of information and data. By using visual elements like charts, graphs, and maps, data visualization tools provide an accessible way to see and understand trends, outliers, and patterns in data.

What statistical graph is best used to show the relative sizes of data?

A pie graph (sometimes called a pie chart) is used to show how an overall total is divided into parts. A circle represents a group as a whole. The slices of this circular “pie” show the relative sizes of subgroups.

Is a table a visual representation?

Tables and graphs are visual representations. They are used to organise information to show patterns and relationships. A graph shows this information by representing it as a shape.

Which visualization technique can be used to understand the relationship between height and weight?

To plot the relationship of just two such variables, e.g. the height and weight, we will normally use a scatter plot.


3 Answers

Borrowing the code of digEmAll I'll do the same in qgraph:

data <- read.table(text=
"Item A,Item B,Weight
X,Y,2
X,Z,5
Y,Z,3
Y,W,2", sep=',',header=TRUE)

library(qgraph)
qgraph(data)

enter image description here

like image 116
SeeLittle Avatar answered Oct 20 '22 10:10

SeeLittle


Another way in R is using plot.igraph(infos about parameters can be found here).

Below you can find a working example (based on your data):

library(igraph)

data <- read.table(text=
"Item A,Item B,Weight
X,Y,2
X,Z,5
Y,Z,3
Y,W,2", sep=',',header=TRUE)

g <- graph.data.frame(data,directed=TRUE)

vColors <- 'MediumSeaGreen'
vSizes <- 40 
vShapes <- 'circle' 
vLabels <- V(g)$name
vFontSizes <- 1.5

eColors <- 'blue'
eArrowSizes <- 1
eWidths <- 1
eLabels <- as.character(E(g)$Weight)
eLTypes <- 'dashed'
eFontSizes <- 1.5

plot(g, layout=layout.fruchterman.reingold,
        vertex.color=vColors, vertex.size=vSizes, vertex.shape=vShapes, 
        vertex.label=vLabels, vertex.label.dist=0, vertex.label.cex=vFontSizes,
        edge.color=eColors, edge.width=eWidths, edge.arrow.size=eArrowSizes,  
        edge.label=eLabels, edge.lty=eLTypes, edge.label.cex=eFontSizes)

enter image description here

EDIT :

Exactly as in the base R plot() function, you can show a legend by adding the following line at the end of previous code:

legend(x=-1,c('X - Foo','Y - Bar','Z - Foo2','W - Bar2'))

Please refer to this documentation for further information.

like image 24
digEmAll Avatar answered Oct 20 '22 10:10

digEmAll


In R, you could use diagram::plotweb

library(diagram)
#sample data
nodes <- LETTERS[23:26]
dat <- expand.grid(nodes,nodes)
dat$Weight <- rpois(16,5)+1

#put data in format for plotweb
datMat <- xtabs(Weight~Var1+Var2,dat)
#no loops
diag(datMat)<-0

#plot
plotweb(datMat)
like image 2
James Avatar answered Oct 20 '22 12:10

James