Use R language ggplot2 to draw points and lines to show the results of Mantel's test~

created at 11-13-2021 views: 27

preview

Mantel data visualization

Recently, I have seen several groups discussing this graph. Today’s article will introduce the implementation of this graph based on scatter points and curved line segments in the lower left corner. The upper right corner is the square heat map, which will not be introduced.

data preparing

The first step is to prepare the data
The first is the coordinate position of the black point. This depends on the amount of data in the heat map in the upper right corner. For example, the heat map at the beginning shows 13 variables, and the position coordinate x of the black point in the diagonal line is 1-14 , Y is also 1-14

The data format is as follows

data format

plot

Read the data and plot

library(readxl)
df1<-read_excel("Cor/exampledf.xlsx",
                sheet = "Sheet1")
df1
library(ggplot2)
ggplot()+
  geom_point(data=df1,aes(x=x,y=y))

plot

Then there are the position coordinates of the bottom four points

coordinates

code

df2<-read_excel("Cor/exampledf.xlsx",
                sheet = "Sheet2")
ggplot()+
  geom_point(data=df1,aes(x=x,y=y))+
  geom_point(data=df2,aes(x=x,y=y))

result

Then there is the data of the connection

data of the connection

code

df3<-read_excel("Cor/exampledf.xlsx",
                sheet = "Sheet3")

ggplot()+
  geom_point(data=df1,aes(x=x,y=y))+
  geom_point(data=df2,aes(x=x,y=y))+
  geom_curve(data=df3,aes(x=xmin,y=ymin,
                          xend=xmax,yend=ymax,
                          color=pvalue,
                          size=rvalue),
             curvature = -0.05)+
  scale_size_continuous(range = c(0.1,1))+
  scale_color_manual(values=c("#b85315","#189164","#bababa"))+
  theme_void()

result

The black dots below are covered by the line segment, we can write the code of the scattered dots at the end.

ggplot()+
  geom_curve(data=df3,aes(x=xmin,y=ymin,
                          xend=xmax,yend=ymax,
                          color=pvalue,
                          size=rvalue),
             curvature = -0.05)+
  scale_size_continuous(range = c(0.1,1))+
  scale_color_manual(values=c("#b85315","#189164","#bababa"))+
  theme_void()+
  geom_point(data=df1,aes(x=x,y=y))+
  geom_point(data=df2,aes(x=x,y=y))

result

created at:11-13-2021
edited at: 11-13-2021: