Questions tagged [ggtext]

Advanced text formatting in ggplot2, enables the rendering of complex formatted plot labels.

The ggtext package enables using (a limited subset of) Markdown and HTML syntax in ggplot2 plot labels.

Repositories:

77 questions
26
votes
4 answers

photo alignment with graph in r

First I thought I need to it manually in powerpoint, then I thought may be try with R, if there is a solution. Here is my example data: set.seed(123) myd<- expand.grid('cat' = LETTERS[1:5], 'cond'= c(F,T), 'phase' = c("Interphase", "Prophase",…
jon
  • 11,186
  • 19
  • 80
  • 132
12
votes
0 answers

Justify multiline text in ggplot2 - title, subtitle, caption, geom_text() etc

I would like to justify (not just align!) multiline text in my ggplots, i.e. mostly title, subtitle, caption and annotations via geom_text() etc. Justified Text To be clear, by "justified text" I mean adding space between words so that both edges of…
Paul Schmidt
  • 1,072
  • 10
  • 23
10
votes
2 answers

How to italicize one category in a legend in ggplot2

For my legend in ggplot2 I have 2 categories, how do I italicize only 1 category and not the other? As an example, consider the following plot. How can I set "Manual" in italics? library(ggplot2) ggplot(data = mtcars, aes(x = as.factor(am), fill =…
Eswim
  • 101
  • 1
  • 1
  • 3
9
votes
2 answers

conditionally fill ggtext text boxes in facet_wrap

Is it possible to conditionally fill these [ggtext][1] text boxes? Let's say color "red" if "pickup". library(cowplot) library(tidyverse) library(ggtext) ggplot(mpg, aes(cty, hwy)) + geom_point() + facet_wrap(~class) + theme_half_open(12)…
Eric Green
  • 7,385
  • 11
  • 56
  • 102
8
votes
1 answer

Best way to add a text-only section in a {patchwork} of multiple ggplots?

When using {patchwork} to combine separate ggplots into the same graphic, I sometimes want to add one or more sections that are no plots at all, but basically a textbox. As far as I can tell, the only time this is adressed in the patchwork…
Paul Schmidt
  • 1,072
  • 10
  • 23
8
votes
2 answers

Is it possible to change the alignment of only 1 facet title

Say I have a facetted ggplot like this: data(iris) ggplot(iris, aes(x = Petal.Width, y = Sepal.Length)) + facet_grid(. ~ Species) + geom_point() Question: Is it possible to align only the 1st facet label ("setosa") to the left, but keep the…
morgan121
  • 2,213
  • 1
  • 15
  • 33
8
votes
1 answer

Text formatting in ggplot's annotate

Is it possible to annotate with html code? I'm trying to color only a few words and not the entire text. library(tidyverse) #> Warning: package 'ggplot2' was built under R version 4.0.2 mtcars %>% ggplot(aes(x = hp, y = mpg)) + geom_point() + …
Alberson Miranda
  • 1,248
  • 7
  • 25
8
votes
1 answer

Render unicode emoji in colour in ggplot2 geom_text

I have unicode text that includes emoji. I'd like to render them in a ggplot2 graphic with geom_text or geom_label in a way that includes the emoji's colour. I've looked at emojifont, emo and ggtext and none of these seem to allow this. The issue of…
Peter Ellis
  • 5,694
  • 30
  • 46
7
votes
1 answer

Colour in title of patchwork of ggplots using ggtext?

How can a patchwork of ggplots be given a colourful title using ggtext? Example Suppose we have four plots library(ggplot2) library(patchwork) library(ggtext) p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) + ggtitle('Plot 1') p2 <-…
stevec
  • 41,291
  • 27
  • 223
  • 311
7
votes
2 answers

Use different font sizes for different portions of text in ggplot2 title

Consider the following graph: require(ggplot2) ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point() + labs(title = 'Iris[small font]' ) + theme_classic() The Left graph is the code output, the right graph shows the desired result, I…
tjebo
  • 21,977
  • 7
  • 58
  • 94
5
votes
2 answers

Left align ggplot caption

I'm using the R package ggtext to "plot align" (max left align) my title and subtitle. I also want to use these ggtext methods to "plot align" my caption. library(tidyverse) library(ggtext) ggplot(mpg, aes(cty, hwy)) + geom_point() + …
Display name
  • 4,153
  • 5
  • 27
  • 75
4
votes
1 answer

Adding images below x-axis labels in ggplot2

I have this plot: Which has been produced with this code chunk based on an old TidyTuesday dataset, Astronaut. library(tidyverse) library(ggplot2) library(ggtext) astro_Q2_final %>% ggplot(aes(x = reorder(nationality, proportion), y =…
4
votes
1 answer

Change font face (to bold) of a single label in ggplot2 legend

I have a dataset in R 4.0.2 of two continuous variables divided into two groups (variable Curve: "Exp." or "Molecular\ndynamics"). I plot them with a geom_smooth layer (ggplot2 3.3.2) and color them by group Curve, and I also set that they are…
4
votes
1 answer

how to apply both italic and normal fonts in the same label in phylogenetic tree in ggtree

I want A in italic, and CBS in normal. I think ggtext might be useful, but I got an error. here is an example: tree<-read.tree(text="(A,(B,C));") labs=c("*A*CBS","B","C") tree$tip.label<-labs ggtree(tree)+ geom_tiplab(align=T) +…
Cai Bian
  • 141
  • 1
  • 6
4
votes
1 answer

ggplot2 facet labels - second line is not displayed

I have a script that used to produce a facetted plot with strip text on multiple lines. But this does not work anymore. Below is a MWE where the strip text should be parsed from, e.g. "bold(A)\nreally~long~extra" to: A really long extra The second…
bamphe
  • 328
  • 3
  • 12
1
2 3 4 5 6