41363

Using Unicode character (plus minus sign) inside ggplot2

Question:

I am trying to build a plot that includes a unicode character (The plus-minus <a href="https://www.compart.com/en/unicode/U+00B1" rel="nofollow">sign</a> U+00B1)

Here is some fake data:

library(tidyverse) set.seed(1) df <- crossing( Rated_Movement = c("Running", "Jumping"), Rater = c("John Snow", "Batman", "Hulk")) %>% mutate( Error = runif(n = 6, min = 0, max=2))

Here is my code for the plot so far:

ggplot(df, aes(x = Rated_Movement, y = Rater, fill = Error)) + geom_tile(color = "black", size = 0.5, alpha = 0.8)+ geom_text(aes(label = paste("+-", round(Error,2))))+ scale_fill_gradientn(colours = terrain.colors(10))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())

Here is the plot:<br /><a href="https://i.stack.imgur.com/gOugL.jpg" rel="nofollow"><img alt="Plot" class="b-lazy" data-src="https://i.stack.imgur.com/gOugL.jpg" data-original="https://i.stack.imgur.com/gOugL.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Is there a way that I can change the +- to unicode character U+00B1

I tried using the backslash to escape: paste("\U+00B1", round(Error,2)) But I get the error: "Error: '\U' used without hex digits in character string starting ""\U""

Any help will be much appreciated. Best regards

Answer1:

here are two ways:

ggplot(df, aes(x = Rated_Movement, y = Rater, fill = Error)) + geom_tile(color = "black", size = 0.5, alpha = 0.8)+ geom_text(aes(label = paste("±", round(Error,2))))+ scale_fill_gradientn(colours = terrain.colors(10))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) ggplot(df, aes(x = Rated_Movement, y = Rater, fill = Error)) + geom_tile(color = "black", size = 0.5, alpha = 0.8)+ geom_text(aes(label = paste("\u00B1", round(Error,2)))) + scale_fill_gradientn(colours = terrain.colors(10))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())

<a href="https://i.stack.imgur.com/iDigA.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/iDigA.png" data-original="https://i.stack.imgur.com/iDigA.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Recommend

  • Require “open-url” load error when executing Nokogiri tester
  • linq joint type inference failed to call 'join' error
  • How to set focus on specific input?
  • Hadoop - HDFS - Command to see how a file's splits
  • R: Reshape from long to wide, order of reshaped columns as original column order [duplicate]
  • Using PHP write an anagram function?
  • javaws : Java 7 update 45. Cannot send properties [duplicate]
  • Highcharts PhantomJS - Alternative Approach
  • Cutting down bag to pass to udf
  • Rails Redirect to an Anchor Tag from the Controller
  • Load page directly to anchor tag
  • How do I implement a picture instead of my red rectangle?
  • Finder Plugin in Snow Leopard
  • Parallelize an R Script
  • how to bypass pinentry (passphrase screen) while decrypting a file using gpgme
  • jqPlot date axis - bars drawn on wrong day?
  • How to add specific media query rule when media query combined
  • How to merge two Request in Laravel
  • Stitching 2 images (OpenCV)
  • Haskell: function composition with anonymous/lambda function
  • Is it safe to drop the -webkit vendor prefix from the css3 border-radius yet?
  • Google analytics measurement protocol session timeout and query time limits
  • How to convert integer to string and get length of string
  • Creating a Multidimensional, Associative Array in VBScript
  • how to get username into sql trigger when multiple users signed on from asp membership
  • RxJava debounce by arbitrary value
  • D3 get axis values on zoom event
  • C: Incompatible pointer type initializing
  • Highlight one bar in a series in highcharts?
  • ActionScript 2 vs ActionScript 3 performance
  • How can I estimate amount of memory left with calling System.gc()?
  • How to get next/previous record number?
  • Apache 2.4 - remove | delete | uninstall
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal