Making a plot in circlize package in R

413 views Asked by At

I have airline connectivity data among different cities. I would like to make a chord diagram with control in color with help of Circize package. I need help

Place1<-c("Delhi","Hongkong","Manila","Delhi","Hongkong","Manila","Delhi","Hongkong","Manila")
Place2<-c("Delhi","Delhi","Delhi","Hongkong","Hongkong","Hongkong","Manila","Manila","Manila")
value<-c(8,21,29,41,23,16,14,8,9)
df1<-cbind(Place1,Place2,value)

the data is like this

Place1     Place2     value
 [1,] "Delhi"    "Delhi"    "8"  
 [2,] "Hongkong" "Delhi"    "21" 
 [3,] "Manila"   "Delhi"    "29" 
 [4,] "Delhi"    "Hongkong" "41" 
 [5,] "Hongkong" "Hongkong" "23" 
 [6,] "Manila"   "Hongkong" "16" 
 [7,] "Delhi"    "Manila"   "14" 
 [8,] "Hongkong" "Manila"   "8"  
 [9,] "Manila"   "Manila"   "9"
1

There are 1 answers

0
s__ On

We can try something like this:

# Here your data:
Place1<-c("Delhi","Hongkong","Manila","Delhi","Hongkong","Manila","Delhi","Hongkong","Manila")
Place2<-c("Delhi","Delhi","Delhi","Hongkong","Hongkong","Hongkong","Manila","Manila","Manila")
value<-c(8,21,29,41,23,16,14,8,9)
# df1<-cbind(Place1,Place2,value)    this is not useful, it's better to put them in a data.frame
df1 <-data.frame(Place1,Place2,value = as.numeric(value))

Then, we can manipulate the data, and have the plot. As stated in this simple example, the data should be put in a table: you have also the values, so we can put them with a base function:

dat <- xtabs(value ~ Place1 + Place2, df1)

Now we can plot the data:

library(circlize)
chordDiagram(as.data.frame(dat), transparency = 0.5)

enter image description here

However, you may consider some other ways to visualize those kinds of data.