Display unicode symbol (not equal to) in ggtitle

user110577

I am trying to get "the not equal to" symbol in the title of my ggplot. The unicode symbol is U+2260. When I run the main_title line in the example below, the symbol is displayed in the console. Example code below:

#Example data
testy <- data.frame(Est = rnorm(10), method2 = paste0("Method", 1:10) )

#Title for plot
main_title <- expression(bold(paste("Sample selection (", psi[3], "\u2260 \u0021 0)")))

##Plotting
ggplot(data = testy, aes(x=method2, y = Est)) + 
  geom_point( ) + 
  geom_hline(yintercept = 0, color= "red", linetype = "dashed") + 
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        legend.position = "none") +
  xlab("") + ylab("") + 
  ggtitle(main_title)  

When the ggplot command is run and the graph is displayed, the "not equal to" symbol converts back to the unicode number in the title. I tried adding in an extra unicode for an exclamation mark (U+0021) to see if the issue was the unicode itself. The exclamation mark unicode displays correctly but the "not equal to" unicode does not.

I have tried using sprintf and printing out as a pdf but the "not equal to" unicode number is displayed in both instances instead of the symbol. If anyone has any suggestions on where I'm going wrong, please let me know.

Allan Cameron

The symbol is directly available using plotmath - just use != in your expression, and it will appear as

ggplot(data = testy, aes(x=method2, y = Est)) + 
  geom_point( ) + 
  geom_hline(yintercept = 0, color= "red", linetype = "dashed") + 
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        legend.position = "none") +
  xlab("") + ylab("") + 
  ggtitle(expression(bold(Sample~selection~(psi[3] != 0))))

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related