Geom_text - Math expression label annotation - color, parsing, and subgraph labeling problems

OK, so first thing's first: getting your code working, and into a proper reprex (short for reproducible example).

If you're new to reprex, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful. For pointers specific to the community site, check out the reprex FAQ.

Note that in order for this to work, I had to load the libraries being used (I could have done library(ggplot2), I just happened not to).

I changed your scale_color_viridis with the discrete = TRUE argument, to scale_color_viridis_d() (the d stands for discrete). You can read more about new functionality for scales and guides in ggplot2 3.0.0 here:

library(tidyverse)
reprex.data <- data.frame(x = c(4.5, 3, 3, 3.5, 3.5, 4, 4, 0), y = c(4.5, 3, 3, 3.5, 3.5, 4, 4, 0), color = c("A", "A", "A", "A", "B", "B", "A", "A"))

ggplot(reprex.data, aes(x = x, y = y, colour = color, shape = color)) +
  geom_point() +
  geom_text(aes(label = "Alpha[qq]%~~%10^10", x = 1.5, y = -3), parse = T, colour = "black", size = 7) +
  scale_color_viridis_d(option = "B", begin = 0.0, end = 0.85, direction = 1) +
  geom_text(aes(label = "(d)", x = 0, y = 5), parse = T, colour = "black", size = 7)

Created on 2018-08-13 by the reprex package (v0.2.0.9000).

Also in ggplot2 3.0.0 is a tag option:

In addition to title, subtitle, and caption, a new tag label has been added, for identifying plots. Add a tag with labs(tag = "A") , style it with the plot.tag theme element, and control position with the plot.tag.position theme.

I didn't add any styling, but here's your example with (d) passed as a tag:

library(tidyverse)
reprex.data <- data.frame(x = c(4.5, 3, 3, 3.5, 3.5, 4, 4, 0), y = c(4.5, 3, 3, 3.5, 3.5, 4, 4, 0), color = c("A", "A", "A", "A", "B", "B", "A", "A"))

ggplot(reprex.data, aes(x = x, y = y, colour = color, shape = color)) +
  geom_point() +
  geom_text(aes(label = "Alpha[qq]%~~%10^10", x = 1.5, y = -3), parse = T, colour = "black", size = 7) +
  scale_color_viridis_d(option = "B", begin = 0.0, end = 0.85, direction = 1) +
  labs(tag = "(d)")

Created on 2018-08-13 by the reprex package (v0.2.0.9000).

I don't have a ready-made solution off the top of my head for the equation at the bottom. Someone else might, though. You could certainly make a helper function, though.

4 Likes