Shakir
Shakir

Reputation: 345

5 value unicode character in ggplot2

The aim is to show ๐‘…. The unicode value \u1D445 is interpreted as \u1D44 + 2 and printed as แต„2 in ggplot2. Any solutions?

library(ggplot2)
library(extrafont)
loadfonts(device = "win")
set.seed(42) 
df <- data.frame(date = 1:10 , value = cumsum(runif(10 , max = 10)) )
p <- ggplot(df, aes(x=date, y=value)) 
p <- p + geom_line()
p + geom_label(aes(label = "Kruskal-Wallis Anova Dim2 by:\nCategory: p < .001\nRegion: p < .001\nCategory*Region: p < .001\n\u1D445\u00B2 = 0.49",  x=2, y=40, family="Times New Roman")

Upvotes: 1

Views: 342

Answers (3)

Shakir
Shakir

Reputation: 345

My dirty solution is not to use \u.

p + geom_label(aes(label = "Kruskal-Wallis Anova Dim2 by:\nCategory: ๐‘ < .001\nRegion: ๐‘ < .001\nCategory*Region: ๐‘ < .001\n๐‘…\u00B2 = 0.49",  x=2, y=40, family="Times New Roman")

it creates problems in displaying the string in R studio. And I am not sure if the letters are really in the same font, and italic versions of normal R and p.

Upvotes: 0

user2554330
user2554330

Reputation: 44788

You are specifying the character using the wrong syntax. \u only takes 4 hex digits, as you saw, but there's also \U which takes up to 8. This is the same syntax as C99.

I can't run your Windows-specific code to test, but that should at least help.

Upvotes: 3

rm167
rm167

Reputation: 1247

This should do what you want

p + geom_label(aes(label = "R",  x=2, y=40, fontface="italic", family="Times New Roman"))

This is an inherent feature included in geom_label, so does not need any other library.

Upvotes: 0

Related Questions