您的代码仍然不能完全重现,因为您还没有定义 A 或 B。这是包中维恩图的指南,venneuler
因为我发现它更灵活。
List1 <- c("apple", "apple", "orange", "kiwi", "cherry", "peach")
List2 <- c("apple", "orange", "cherry", "tomatoe", "pear", "plum", "plum")
Lists <- list(List1, List2) #put the word vectors into a list to supply lapply
items <- sort(unique(unlist(Lists))) #put in alphabetical order
MAT <- matrix(rep(0, length(items)*length(Lists)), ncol=2) #make a matrix of 0's
colnames(MAT) <- paste0("List", 1:2)
rownames(MAT) <- items
lapply(seq_along(Lists), function(i) { #fill the matrix
MAT[items %in% Lists[[i]], i] <<- table(Lists[[i]])
})
MAT #look at the results
library(venneuler)
v <- venneuler(MAT)
plot(v)
编辑:头部非常有帮助,因为它给了我们一些可以使用的东西。试试这个方法:
#For reproducibility (skip this and read in the csv files)
A <- structure(list(V1 = structure(1:6, .Label = c("PSF113_0016a",
"PSF113_0018", "PSF113_0079", "PSF113_0079a", "PSF113_0079b",
"PSF113_0079c"), class = "factor")), .Names = "V1",
class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6"))
B <- structure(list(V1 = structure(1:10, .Label = c("PSF113_0016a",
"PSF113_0021", "PSF113_0048", "PSF113_0079", "PSF113_0079a",
"PSF113_0079b", "PSF113_0079c", "PSF113_0295", "PSF113_0324a",
"PSF113_0324b"), class = "factor")), .Names = "V1",
class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10"))
从这里运行代码:
#after reading in the csv files start here
Lists <- list(A, B) #put the word vectors into a list to supply lapply
Lists <- lapply(Lists, function(x) as.character(unlist(x)))
items <- sort(unique(unlist(Lists))) #put in alphabetical order
MAT <- matrix(rep(0, length(items)*length(Lists)), ncol=2) #make a matrix of 0's
colnames(MAT) <- paste0("List", 1:2)
rownames(MAT) <- items
lapply(seq_along(Lists), function(i) { #fill the matrix
MAT[items %in% Lists[[i]], i] <<- table(Lists[[i]])
})
MAT #look at the results
library(venneuler)
v <- venneuler(MAT)
plot(v)
这种方法的不同之处在于我没有列出两个数据帧(如果它们是数据帧),然后将它们转换为字符向量。我认为这应该有效。