如何在 R 中制作 scatterplot/bubble 图表,包括来自两个矩阵的连续离散变量

How to make a scatterplot/bubble chart in R including continuous an discrete variables from two matrices

我有两个数据矩阵(这是一个例子):

矩阵 1:基因型(缺少数据)

NA NA HOM HET HOM
NA NA HOM HET HOM
NA NA HOM HET HOM
NA NA HOM HET HOM
NA NA HOM HET HET

矩阵 2:读取计数

0 0 1 2 2
0 0 1 2 2
0 0 1 2 2
0 0 1 2 3
0 0 1 2 3

我想在 R 中创建类似于此绘图的 scatterplot/bubble 图表:

这是另一个答案。它很相似,但与 Rawr 采用的方法有一些不同,主要是我假设数据是矩阵(而不是数据帧)并使用了另一个绘图引擎。

library(reshape2)
library(ggplot2)
#combine the data, as we need to be able to count each occurence of combinations
#assumes data are in matrices. converts to dataframe because of different types
mydat <- data.frame(geno=as.vector(geno),
                    readcount=as.vector(readcounts))


#remove missings
mydat <- mydat[!is.na(mydat$geno),]


#aggregate using reshape

plotdata <- dcast(geno+readcount~"count", 
data=mydat, fun.aggregate = length, value.var="readcount")

#plot

p1 <- ggplot(plotdata, aes(x=readcount,y=geno)) +
  geom_point(aes(size=count)) +
  scale_x_continuous(breaks=1:3)+
  theme_bw()
p1