0

I created a plot (and set the diagonals = 0) that looks like this:

Plot ex 1

But what I'm trying to achieve is something like this (which I made in powerpoint):

Plot ex 2

So, basically what Im wondering is if it's possible to have 2 separate measurements on the one plot and if so, how would I try and achieve this?

Any suggestions?

Thanks

Electrino
  • 2,636
  • 3
  • 18
  • 40

1 Answers1

0

It is generally a bad idea to combine to different types of data in the same plot. If you are going to do it, it is best if they are visually distinct. So, here is one approach to get what you want.

First, some sample data:

temp_data <-
  tibble(
    A = paste0("x", 1:5)
    , B = paste0("x", 1:5)
  ) %>%
  complete(A, B) %>%
  mutate(interaction = runif(n(), 0, 10)
         , Other = runif(n(), 0, 100))

Then, the plot, note that I am using two different geometries and filtering to only display the one I want for each (you could also do this from completely separate data frames if, for example, your secondary measure was stored somewhere else).

ggplot() +
  geom_raster(
    aes(x = A
        , y = B
        , fill = interaction)
    , temp_data %>%
      filter(A != B)
  ) +
  geom_point(
    aes(x = A
        , y = B
        , color = Other)
    , temp_data %>%
      filter(A == B)
    , size = 5
  ) +
  scale_fill_distiller(palette = "Blues") +
  scale_color_distiller(palette = "Reds")

Results in:

enter image description here

Mark Peterson
  • 9,370
  • 2
  • 25
  • 48
  • This was definitely the direction I wanted to go in before the question got closed. But I can't seem to adapt it to my code – Electrino Oct 22 '19 at 22:59