Reputation: 1057
I have a binary files that is 1440 columns*720 rows. I read it into R as a matrix in order to plot it as scatter plot, but I wonder why the resulting plot was something weird (I do not have enough rep to upload the plot).
conner <- file("D:\\complete.bin","rb")
corrs <- readBin(conner, numeric(), size=4, n=1440*720, signed=TRUE)
y1 <- t(matrix((data=corrs), ncol=720, nrow=1440))
plot(y1)
so I want to convert the matrix to be:
(5,4,5,2,1,6,9,8,......................................)all values
and plot them as a scatter plot.
So how can we plot a matrix as scatter plot and not as an image?
Upvotes: 1
Views: 36590
Reputation: 6477
So you want to plot all the values in your matrix. You can do it like this:
y<-matrix(rnorm(25),5,5)
y
[,1] [,2] [,3] [,4] [,5]
[1,] 1.8185601 0.6745425 0.5584071 -1.0631574 -0.6729403
[2,] -0.5075942 1.8931653 0.9951502 -1.0469745 0.3087902
[3,] -0.8855172 -0.5571970 0.8180533 -1.6210277 1.0537248
[4,] 0.2876082 0.1775348 1.2246795 0.7912057 -1.3986548
[5,] -0.2157624 -0.4067569 1.0355421 -0.7114979 -0.2311551
plot(c(y))
But in you case you already have a vector corrs
so just use plot(corrs)
.
Upvotes: 9
Reputation: 5566
I'm assuming corrs is an image of your precomputed scatterplot.
Try
image(matrix((data=corrs), ncol=720, nrow=1440))
or
library(fields)
image.plot(matrix((data=corrs), ncol=720, nrow=1440))
Upvotes: 4