What techniques exists in R to visualize a “distance matrix”?

前端 未结 7 1306
你的背包
你的背包 2020-12-12 10:16

I wish to present a distance matrix in an article I am writing, and I am looking for good visualization for it.

So far I came across balloon plots (I used it here, b

7条回答
  •  半阙折子戏
    2020-12-12 10:52

    Tal, this is a quick way to overlap text over an heatmap. Note that this relies on image rather than heatmap as the latter offsets the plot, making it more difficult to put text in the correct position.

    To be honest, I think this graph shows too much information, making it a bit difficult to read... you may want to write only specific values.

    also, the other quicker option is to save your graph as pdf, import it in Inkscape (or similar software) and manually add the text where needed.

    Hope this helps

    nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv")
    
    dst <- dist(nba[1:20, -1],)
    dst <- data.matrix(dst)
    
    dim <- ncol(dst)
    
    image(1:dim, 1:dim, dst, axes = FALSE, xlab="", ylab="")
    
    axis(1, 1:dim, nba[1:20,1], cex.axis = 0.5, las=3)
    axis(2, 1:dim, nba[1:20,1], cex.axis = 0.5, las=1)
    
    text(expand.grid(1:dim, 1:dim), sprintf("%0.1f", dst), cex=0.6)
    

提交回复
热议问题