visualize associations between two groups of data

前端 未结 4 962
清酒与你
清酒与你 2021-01-06 20:11

Where each datapoint has a pairing of A and B and there multiple entries in A and multiple entires in B. IE multiple syndromes and multiple diagnoses, although for each data

4条回答
  •  春和景丽
    2021-01-06 20:31

    Since your data is bipartite, I would suggest plotting points in the first factor on one side, points in the other factor on the other, with lines between them, like so:

    enter image description here

    The code I used to generate this was:

    ## Make up data.
    data <- data.frame(X1=sample(state.region, 10),
                       X2=sample(state.region, 10))
    
    ## Set up plot window.
    plot(0, xlim=c(0,1), ylim=c(0,1),
         type="n", axes=FALSE, xlab="", ylab="")
    
    factor.to.int <- function(f) {
      (as.integer(f) - 1) / (length(levels(f)) - 1)
    }
    
    segments(factor.to.int(data$X1), 0, factor.to.int(data$X2), 1,
             col=data$X1)
    axis(1, at = seq(0, 1, by = 1 / (length(levels(data$X1)) - 1)),
         labels = levels(data$X1))
    axis(3, at = seq(0, 1, by = 1 / (length(levels(data$X2)) - 1)),
         labels = levels(data$X2))
    

提交回复
热议问题