Why does the image() function not work properly?

后端 未结 2 1367
不知归路
不知归路 2021-01-17 07:05

I have big binary matrix (0,1) and I want to visualize it so that every entry of my matrix is one pixel in the plot. I use the image() function, but it does not

2条回答
  •  猫巷女王i
    2021-01-17 07:38

    As the image plots the counter-clockwise rotation of the input matrix, you have to transpose it and then flip it to be normally plotted:

    tb <- t(b)
    ftb <- tb[ , ncol(tb):1]
    

    Now you can use custom colors if you don't like the default ones, e.g. 0 is grey and 1 is red. Also using the asp equal to one makes each pixel of the image rectangular (from @koekenbakker's comment ).

    image(x=1:2, y=1:4, ftb, col = c("grey", "red"), asp = 1)
    

    enter image description here

提交回复
热议问题