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.
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.
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.
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.
To plot the relationship of just two such variables, e.g. the height and weight, we will normally use a scatter plot.
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)
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)
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With