R data visualization-Bubble Matrix

created at 08-06-2021 views: 16

Step1. Preparation of drawing data

First, adjust the data you want to plot into a format that can be recognized by the R language. It is recommended that you save it in csv format in excel.

datastructure:

datastructure

Step2. Read data

data<-read.csv("your file path", header = T)
  • header=T means that the first row in the data is the column name, if there is no column name, use header=F

Step3. packages required for plotting

library(reshape2)
library(ggplot2)                          

Step4. plotting

data_melt<-melt (data)
names(data_melt) = c('Gene', 'Cell', 'Value')

p<-ggplot(data_melt, aes(x = Gene, y = Cell, size = Value, color=Cell)) + geom_point()
  • The melt() function turns the wide data in the table into long data

Bubble Matrix

Step5. Beautify

p<-ggplot(data_melt, aes(x = Gene, y = Cell, size = Value, color=Cell)) + geom_point()+
  theme(panel.background = element_blank(),
        panel.grid.major = element_line(colour = "gray"),
        panel.border = element_rect(colour="black",fill=NA))
  • panel.background = element_blank(): chanage original gray background to transparent
  • panel.grid.major = element_line(colour = "gray"): change color of grid lines to be gray
  • panel.border = element_rect(colour="black",fill=NA): change border color to black

final result

created at:08-06-2021
edited at: 08-06-2021: