Reputation: 345
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
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
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
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