I have a vector of numerical values, say:
angles <- c(10.2, 20.3, 14.3, 18.4)
And I want to append the degree symbol at the end of each element, in order to obtain:
labels <- c("10.2°", "20.3°", "14.3°", "18.4°")
I tried with bquote() function without success:
labels <- bquote(paste(.(angles) * degree))
If your keyboard does not provide the degree symbol °
the character can be obtained with its UTF8 code, which in this case is 176:
paste0(angles,intToUtf8(176))
#[1] "10.2°" "20.3°" "14.3°" "18.4°"
By using the UTF8 code any character can be pasted like this. Hope this helps.
If you are wanting to use the labels on a plot, code like this would work
angles <- c(10.2, 20.3, 14.3, 18.4)
labels <-sapply(angles, function(a)bquote(.(a) * degree))
plot(1:4, 1:4)
mapply(text, labels = labels, x = 1:4, y = 1:4, pos = 4:1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With