簡體   English   中英

如何在R中制作散點圖/氣泡圖,包括來自兩個矩陣的連續離散變量

[英]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中創建一個散點圖/氣泡圖,類似於此圖:

在此處輸入圖片說明

這是另一個答案。 它是相似的,但是與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

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM