如何显示R中变量之间的成对关系?

How to display pairwise relationship between variables in R?

如果"UniqueCarrier"是一个字符,"Delay"包含0和1,如何显示变量之间的成对关系?

plot(Delay ~ UniqueCarrier, data = mydata)

我们可以按以下方式使用 barplot 来显示字符变量的每个唯一值的 1 的计数

# Generate sample data
uniqueCarrier <- unlist(lapply(1:10, function(i) rep(paste(sample(letters,size = 3), collapse=""),10)))
Delay <- rbinom(100, 1, prob = rep(c(.30, .2, .1, .5, .7, .6, .9, .2, .7, .6),each = 10))

# Create the plot
barplot(by(data = Delay, INDICES = uniqueCarrier, sum), cex.names = 0.9)

已生成数据

> dput(uniqueCarrier)
c("ekp", "ekp", "ekp", "ekp", "ekp", "ekp", "ekp", "ekp", "ekp", 
"ekp", "vtq", "vtq", "vtq", "vtq", "vtq", "vtq", "vtq", "vtq", 
"vtq", "vtq", "jic", "jic", "jic", "jic", "jic", "jic", "jic", 
"jic", "jic", "jic", "sab", "sab", "sab", "sab", "sab", "sab", 
"sab", "sab", "sab", "sab", "ekl", "ekl", "ekl", "ekl", "ekl", 
"ekl", "ekl", "ekl", "ekl", "ekl", "ifx", "ifx", "ifx", "ifx", 
"ifx", "ifx", "ifx", "ifx", "ifx", "ifx", "miw", "miw", "miw", 
"miw", "miw", "miw", "miw", "miw", "miw", "miw", "oif", "oif", 
"oif", "oif", "oif", "oif", "oif", "oif", "oif", "oif", "qto", 
"qto", "qto", "qto", "qto", "qto", "qto", "qto", "qto", "qto", 
"vqw", "vqw", "vqw", "vqw", "vqw", "vqw", "vqw", "vqw", "vqw", 
"vqw")
> dput(Delay)
c(1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 
1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 
0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 
1L, 1L, 0L, 1L, 0L)