jokergoo / ComplexHeatmap

Make Complex Heatmaps
https://jokergoo.github.io/ComplexHeatmap-reference/book/
Other
1.26k stars 220 forks source link

bold, italic #883

Open byeongchangsim opened 2 years ago

byeongchangsim commented 2 years ago

Hi guys I have one question. Is there any way to use both bold and italic when using the labels_row command?

If you have any good ideas, please suggest them.

My problem is not using bold and italic for some names of rows, but using both methods to convert row names. Just like the Gene name in the photo below

Thank you. image

jokergoo commented 2 years ago

Do you mean you want to put italic font and bold font in a single string? If so, you can wrap the text in markdown format, and remember to assign to row_labels argument.

m = matrix(rnorm(100), 10)
row_labels = paste0("*", letters[1:10], "*-**", LETTERS[1:10], "**")
Heatmap(m, row_labels = gt_render(row_labels))
image

For more details of gr_render(), please refer to https://jokergoo.github.io/ComplexHeatmap-reference/book/integrate-with-other-packages.html#gridtext

luongphekidz07 commented 2 years ago

Hi @jokergoo,

Thank you for your reply. I think byeongchangsim also want to make the row names in italics. Could you give us the suggestions, Thank you

jokergoo commented 2 years ago

@luongphekidz07 cann't you do row_names_gp = gpar(fontface = "italic")?

junli1988 commented 1 year ago
row_labels = paste0("*", letters[1:10], "*-**", LETTERS[1:10], "**")
Heatmap(m, row_labels = gt_render(row_labels))

I wanted to try something similar on my rowAnnotation text too. Make the gene names bold AND italic. The suggested method of wrapping the text in gt_render() followed by labels_gp=gpar(fontface="italic") doesn't seem to work on the singular gene label. The first wrapper always overrides the labels_gp command line and I end up with only a bolded text. Here's an example of the code that I tried:

m = matrix(rnorm(100), 10)
row_labels = paste0("*", letters[1:10], "*-**", LETTERS[1:10], "**")
label_at = as.integer(5)
label_text=c("Gene1")
Heatmap(m, row_labels = gt_render(row_labels,gpar(fontface="bold")),
        row_names_gp = gpar(fontface="italic"),
        row_names_side = "left",
        ) + rowAnnotation(label = anno_mark(at = label_at, labels = gt_render(label_text,
                                                                             gp=gpar(fontface="bold")), 
                                            labels_gp = gpar(fontface = "italic")))

What am I doing wrong here? The gt_render works just fine on the row names, but not the "Gene1" text on the right side.

jokergoo commented 1 year ago

Yes, if gr_render() is used, labels_gp in anno_mark() is ignored.

There are three ways to set both italic and bold:

labels = gt_render("*Gene1*", gp=gpar(fontface="bold"))
labels = gt_render("**Gene1**", gp=gpar(fontface="italic"))
# or 
labels = "Gene1", labels_gp = gpar(fontface = 4), ...  # 4 means both italic and bold, or fontface = "bold.italic". Check the documentation of gpar()
junli1988 commented 2 months ago

Thanks! I didn't know about the fontface=4 trick.