我有一张表,其中包含多个样本中丰富的物种。我想制作一个气泡图,其中在y轴上我将有不同的物种,在x轴上我找到那些物种的不同样品,而气泡的半径将表明物种的相对大小。
我的表是这样的:
Samples Sample1 Sample2 Sample3 Sample4 Sample5
Species1 12 25 25 25 25
Species2 12 23 23 23 23
Species3 12 21 21 21 21
Species4 12 19 19 19 19
Species5 12 17 17 17 17
Species6 1 15 15 15 15
Species7 5 13 13 13 13
我希望最终得到类似this的内容:
答案 0 :(得分:0)
tidyr
和ggplot2
:
library(tidyverse)
data <- read.table(text = "Samples Sample1 Sample2 Sample3 Sample4 Sample5
Species1 12 25 25 25 25
Species2 12 23 23 23 23
Species3 12 21 21 21 21
Species4 12 19 19 19 19
Species5 12 17 17 17 17
Species6 1 15 15 15 15
Species7 5 13 13 13 13", header = T)
data %>%
gather(sample, value, Sample1:Sample5) %>%
ggplot(aes(sample, Samples, size = value)) +
geom_point()
答案 1 :(得分:0)
这是一个基本解决方案:
df <- read.table(text="Samples Sample1 Sample2 Sample3 Sample4 Sample5
Species1 12 25 25 25 25
Species2 12 23 23 23 23
Species3 12 21 21 21 21
Species4 12 19 19 19 19
Species5 12 17 17 17 17
Species6 1 15 15 15 15
Species7 5 13 13 13 13", header=T)
df <- reshape2::melt(df)
par(mar=c(4.1,6.1,2.1,4.1), xpd=T)
plot(y=as.integer(df$Samples), x=as.integer(df$variable), pch=20, cex=df$value/10, bty="n", axes = F, xlab="", ylab="")
axis(2, at = unique(as.integer(df$Samples)), labels = levels(df$Samples), line = 0.5, las=2)
axis(1, at = unique(as.integer(df$variable)), labels = levels(df$variable), line = 0.5)
legend(y=max(as.integer(df$Samples)/1.5), x=max(as.integer(df$variable))+0.25, legend = c(1,5,10,15,20,25), pch = 20, bty="n", pt.cex=c(1,5,10,15,20,25)/10)