Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
B-1991-ing opened this issue Mar 14, 2023 · 7 comments

Comments

@B-1991-ing
Copy link

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
Copy link
Owner

Hy4m commented Mar 26, 2023

you can

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

@B-1991-ing
Copy link
Author

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
Copy link
Author

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

@B-1991-ing
Copy link
Author

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
Copy link
Owner

Hy4m commented Apr 2, 2023

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
Copy link
Author

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
Copy link
Owner

Hy4m commented Apr 18, 2023

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

@Hy4m Hy4m closed this as completed Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants