Hy4m / linkET

Everything is Linkable
135 stars 38 forks source link

Feature requirement for showing the positive or negative correlation in the plot #12

Closed B-1991-ing closed 1 year ago

B-1991-ing commented 1 year ago

Hi Houyun,

Could you add one feature requirement to show the negative correlation using the dotted curves and the positive correlation using the solid curves? Then it will be easier for people to directly see the negative or positive correlation between two matrixes.

For now, all my correlated curves are solid. image

Best,

Bing

Hy4m commented 1 year ago

you can

set linetype = 'dashed' parameter in geom_couple() layer function.

B-1991-ing commented 1 year ago

Is there a way to set the negative Mantel's r with dashed lines and positive Mantel's r with solid lines? If directly set the livetype = "dashed", all lines will be dashed.

image

B-1991-ing commented 1 year ago

I also want to know the positive or negative relationship between the matrixes.

B-1991-ing commented 1 year ago
Screenshot 2023-04-01 at 09 37 34

Hi Houyun,

Is it difficult to add the feature of the solid and dashed lines to make a difference between the positive or negative mantel test relationships, as shown above?

Best,

Bing

Hy4m commented 1 year ago

This part is the same as pure ggplot2, you need to map the linetype to mantel's r and then adjust it using scale_linetype_manual().

Here's an example:

library(linkET)
library(ggplot2)
library(dplyr)
data("varechem", package = "vegan")
data("varespec", package = "vegan")

mantel <- mantel_test(varespec, varechem,
                      spec_select = list(Spec01 = 1:7,
                                         Spec02 = 8:18,
                                         Spec03 = 19:37,
                                         Spec04 = 38:44)) %>% 
  mutate(rd = cut(r, breaks = c(-Inf, 0.2, 0.4, Inf),
                  labels = c("< 0.2", "0.2 - 0.4", ">= 0.4")),
         pd = cut(p, breaks = c(-Inf, 0.01, 0.05, Inf),
                  labels = c("< 0.01", "0.01 - 0.05", ">= 0.05")))

qcorrplot(correlate(varechem), type = "lower", diag = FALSE) +
  geom_square() +
  geom_couple(aes(colour = pd, size = rd, linetype = r > 0), 
              data = mantel, 
              curvature = nice_curvature()) +
  scale_fill_gradientn(colours = RColorBrewer::brewer.pal(11, "RdBu")) +
  scale_size_manual(values = c(0.5, 1, 2)) +
  scale_colour_manual(values = color_pal(3)) +
  scale_linetype_manual(values = c("TRUE" = "solid", "FALSE" = "dashed")) +
  guides(size = guide_legend(title = "Mantel's r",
                             override.aes = list(colour = "grey35"), 
                             order = 2),
         colour = guide_legend(title = "Mantel's p", 
                               override.aes = list(size = 3), 
                               order = 1),
         fill = guide_colorbar(title = "Pearson's r", order = 3))
B-1991-ing commented 1 year ago
Screenshot 2023-04-02 at 11 48 39

image

Yeah, thank you Houyun. I also added the code on making my own plots. But, in both figures, why all significant Mantel's r are positive related lines and only some non-significant Mantel's r represent negative relationship? Is it a bit strange?

Best,

Bing

Hy4m commented 1 year ago

Whether the result is reasonable or not requires professional knowledge to judge.😂