wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
651 stars 37 forks source link

Error message: unsupported tags? #48

Closed alewh2o closed 3 years ago

alewh2o commented 3 years ago

Howdy,

The package ggtext is wonderful for simplifying labels in ggplot using element_markdown. It was working fine about a week ago, but it is now giving the following error message:

Error: gridtext has encountered a tag that isn't supported yet:

Only a very limited number of tags are currently supported.

I've reproduced the issue as shown below. The only tags that I am using are for superscript and line break. I am using R version 4.0.2 with RStudio version 1.2.5003, and all my packages are up to date.

Thank you in advance for your assistance!

library(ggplot2)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggtext)
library(RColorBrewer)

df = mtcars

# Labels with 
labs = c("Within Budget",
         ">0,<br><3 months",
         "<50 m<sup>3</sup>,<br>≥3 months"
         )
my.pal = brewer.pal(3,"Set1")

p = ggplot(df, aes(x=hp, y=mpg, color = factor(gear))) +
  geom_point(stat="identity") +
  scale_color_manual(values = my.pal,
                     aesthetics = "color",
                     labels = labs) +
  theme(legend.position = "bottom",
        legend.text = element_markdown(size=8)
        )
p
#> Error: gridtext has encountered a tag that isn't supported yet: <blockquote>
#> Only a very limited number of tags are currently supported.

Created on 2020-09-12 by the reprex package (v0.3.0)

clauswilke commented 3 years ago

Since you're de-facto writing html, > and < signs need to be encoded with &gt; and &lt;.

library(ggplot2)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggtext)
library(RColorBrewer)

df = mtcars

# Labels with 
labs = c("Within Budget",
         "&gt;0,<br>&lt;3 months",
         "&lt;50 m<sup>3</sup>,<br>≥3 months"
)
my.pal = brewer.pal(3,"Set1")

p = ggplot(df, aes(x=hp, y=mpg, color = factor(gear))) +
  geom_point(stat="identity") +
  scale_color_manual(values = my.pal,
                     aesthetics = "color",
                     labels = labs) +
  theme(legend.position = "bottom",
        legend.text = element_markdown(size=8)
  )
p

Created on 2020-09-13 by the reprex package (v0.3.0)

alewh2o commented 3 years ago

Hi Claus, thank you for pointing that out. It was an awfully simple mistake. Best regards.

tylerlittlefield commented 2 years ago

I am also running into this issue with the following reprex:

library(ggplot2)
library(ggtext)

data <- data.frame(x = c(1:1000), y = c(1:1000))

data %>% 
  ggplot(aes(x, y)) +
  geom_point() +
  geom_richtext(aes(y = y, label = format(y, big.mark = ",")))

Some observations:

  1. Removing the format call resolves the issue
  2. If there is only one data point x = 1000, y = 1000 it doesn't break