0

I'm working with the data that represents n signals and their values in m different time moments (m ~ 1500, n ~ 50). I came up with the algorithm to check which values are representative for each signal and which are not, so I get n signals and m True/False values that tell me if the value is representative or not. I also know that True/False values are grouped pretty well, which means that if I take two close-by values, probability that they are the same is much higher, than that they are different. I'm working in R.

I want to visualize the result of this algorithm output. In order to do this I'm trying to do a raster plot, on which every point is filled with the value of the signal and every group of True/False values has a boarder that is visible. Similar to the picture below, but a bit different.

enter image description here

I'm also open to suggestions of other ways how to visualize this data.

I have one matrix n * m that gives me data to make a raster plot and another matrix n * m (of True/False values) that tells me which points are good/bad.

Code below is the closest I got to the answer, but there is still a boarder inside the group, which is not something that works for me.

library(ggplot2)

n = 5
m = 10

dataMatrix <- data.frame(cbind(1:m, matrix(runif(n * m), ncol = n)))
trueMatrix <- data.frame(cbind(1:m, matrix(rep(c(T, T, T, F, F), m), ncol = n)))

dataMatrix <- gather(dataMatrix, key = Signal, value = Value, -1)
trueMatrix <- gather(trueMatrix, key = TrueFalse, value = Value, -1)

dataMatrix$Representativeness <- trueMatrix$Value
dataMatrix$Signal <- as.integer(gsub("X", "", dataMatrix$Signal))

ggplot(data = dataMatrix) +
  geom_raster(mapping = aes(x = X1, y = Signal, fill = Value)) +
  scale_fill_gradient2(low = "blue", high = "red", na.value = "black", name = "") +
  geom_rect(mapping = aes(xmin = X1 - 0.5,     xmax = X1 + 0.5,
                          ymin = Signal - 0.5, ymax = Signal + 0.5),
            size = 1, fill = NA, colour = dataMatrix$Representativeness)
Ian
  • 53
  • 9
  • I found the post that is asking similar question, which I wasn't able to find before. However, they don't answer the last part of the question, where I need to drow boarder around groups. Trying to figure this out. Will delete/answer here when I will. https://stackoverflow.com/questions/13258454/marking-specific-tiles-in-geom-tile-geom-raster – Ian Oct 30 '19 at 17:59
  • Found another post that can be helpful https://stackoverflow.com/questions/33530055/add-raster-to-ggmap-base-map-set-alpha-transparency-and-fill-color-to-inset-r – Ian Oct 30 '19 at 18:49
  • I have intermediate solution like this: geom_rect(mapping = aes(xmin = X1 - 0.5, xmax = X1 + 0.5, ymin = Signal - 0.5, ymax = Signal + 0.5), size = 1, fill = as.numeric(!dataMatrix$Representativeness) + 0.1, alpha = 0.3). But it doesn't look very appealing visually. – Ian Oct 30 '19 at 19:16

0 Answers0