Hy4m / linkET

Everything is Linkable
145 stars 39 forks source link

How can I use the subscription or superscription in LinkET #16

Closed evian999 closed 1 year ago

evian999 commented 1 year ago

as the title, and i had tried several ways to achieve this.

here's the figure with problem, and code attach it. Figure is the result when try the function ggtext::element_markdown and scale_x_discrete as description above. github issues

qcorrplot(correlate(na.omit(eda.lon[,3:9])), type = "lower", diag = F)+
  geom_square() +
  # geom_tile()+
  scale_x_discrete(labels = eda.abbr)+
  scale_y_discrete(labels = eda.abbr)
  geom_couple(aes(colour = pd, size = rd), 
              data = mantel.mod, 
              curvature = nice_curvature()) +
  # geom_mark(r = NA,size = 3,only_mark = T)+
  scale_fill_gradientn(colours = RColorBrewer::brewer.pal(11, "RdBu"),breaks = seq(1, -1, -0.4),limits = c(-1,1)) +
  scale_size_manual(values = c(0.5, 1, 2)) +
  scale_colour_manual(values = color_pal(3)) +
  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))+
  theme(
    axis.text = element_markdown(color = "black",size = 10))
Hy4m commented 1 year ago

Instead of manually adding scale_x/y_*() to the qcorrplot() function, we can set parse = TRUE in qcorrplot() to handle the subscript/superscripts of axis labels, as shown in the following example:

library(linkET)

d <- mtcars
names(d) <- c("NH^4", names(d)[-1L])

correlate(d) |>
  qcorrplot(parse = TRUE) +
  geom_square()

Note that linkET uses a style similar to LaTex to distinguish between superscripts and subscripts, for example:

x <- "label^{this is superscript}_{this is subscript}"
evian999 commented 1 year ago

Thank you so much! your answer perfectly solve my problem and I believe your answer will also benefit many people who encounter the same error like me, due to I have read various articles about "how to present special sympols like superscription" with this package. However, none of those solutions actually work. Overall, I really appreciate your reply! And I will close this issue later.

Instead of manually adding scale_x/y_*() to the qcorrplot() function, we can set parse = TRUE in qcorrplot() to handle the subscript/superscripts of axis labels, as shown in the following example:

library(linkET)

d <- mtcars
names(d) <- c("NH^4", names(d)[-1L])

correlate(d) |>
  qcorrplot(parse = TRUE) +
  geom_square()

Note that linkET uses a style similar to LaTex to distinguish between superscripts and subscripts, for example:

x <- "label^{this is superscript}_{this is subscript}"