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

Using richtext with annotate() #8

Closed
krassowski opened this issue Nov 27, 2019 · 3 comments
Closed

Using richtext with annotate() #8

krassowski opened this issue Nov 27, 2019 · 3 comments

Comments

@krassowski
Copy link
Contributor

I have tried using the geom_richtext with annotate in two ways, both of which failed:

annotate(geom='richtext', x=8, y=4, label='<i>potential outlier?</i>')

or

annotate(geom='geom_richtext', x=8, y=4, label='<i>potential outlier?</i>')

with:
Error: Can't find `geom` called "(geom_)richtext"

and

annotate(geom=GeomRichText, x=8, y=4, label='<i>potential outlier?</i>')

with:

Error in `[.unit`(padding, c(1, 3)) : 
  index out of bounds ('unit' subsetting)
Calls: <Anonymous> ... convertHeight -> convertUnit -> is.unit -> [ -> [.unit

If this is just an unexplored corner case (and not something which would require a lot of work), this could be very useful to have. A full example:

library(ggplot2)
library(ggtext)

ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
  geom_point(size = 3) +
  scale_color_manual(
    name = NULL,
    values = c(setosa = "#0072B2", virginica = "#009E73", versicolor = "#D55E00"),
    labels = c(
      setosa = "<i style='color:#0072B2'>I. setosa</i>",
      virginica = "<i style='color:#009E73'>I. virginica</i>",
      versicolor = "<i style='color:#D55E00'>I. versicolor</i>")
  ) +
  labs(
    title = "**Fisher's *Iris* dataset**  
    <span style='font-size:9pt'>Sepal width vs. sepal length for three *Iris*
    species</span>",
    x = "Sepal length (cm)", y = "Sepal width (cm)"
  ) +
  annotate(geom='richtext', x=8, y=4, label='<i>potential outlier?</i>') +
  theme_minimal() +
  theme(
    plot.title = element_markdown(lineheight = 1.1),
    legend.text = element_markdown(size = 11)
  )
@krassowski
Copy link
Contributor Author

Thank you!

@clauswilke
Copy link
Collaborator

Thanks, this should work now.

Going forward, please remove any unneeded code from your reprex, to focus on the key issue (see my example below). Also, I strongly suggest using the reprex package. It makes your life easier while making certain your examples are truly reproducible.

library(ggplot2)
library(ggtext)

ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
  geom_point(size = 3) +
  annotate(geom='richtext', x=8, y=4, label='<i>potential outlier?</i>') +
  coord_cartesian(clip = "off")

Created on 2019-11-27 by the reprex package (v0.3.0)

@krassowski
Copy link
Contributor Author

Sorry about that (I will limit the examples to minimum), but I cannot get reprex working for me (it was working in RStudio on my old PC, but because it was not updated for Ubuntu 19.10 and install fails with security issues I had to give up; then I was fighting with getting reprex to display the markdown instead of rendering in the browser, but could not - there are issues open for these problems already).

I am only saying that it is not so easy for everyone to make use of reprex as it may seem, despite an honest effort and an hour less of my time spend on fighting with it :(

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