Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a hyphen, not minus sign, when using expression() to label in R?

I'm using expression() in my plot's x-axis label to create a square-root symbol over my measure's name to indicate that the data has been transformed using square-root transformation. However, my measure's name ("CES-D") has a hyphen in it. When I write it in the expression(), the hyphen becomes a minus or en dash character with space around it.

qplot(1:10, 1:10) + 
    labs(x = expression(sqrt(CES-D~scores)), 
         y = "CES-D scores")

Hyphens different in x and y axis labels

Notice the hyphens are different in the x and y axis labels. In the x-axis label, it looks like square root of "CES minus D scores".

How do I make a regular hyphen character inside an expression() for text?

like image 896
LC-datascientist Avatar asked Feb 22 '18 02:02

LC-datascientist


People also ask

Is hyphen same as minus sign?

The minus and hyphen sign are the same thing. A hyphen is a short, single-character line which connects word parts (i.e. ice-cream). A dash is a longer line—double the length of a hyphen—which indicates a break or an interruption in the thought. Dashes are used to set off part of a sentence.

How do I type an em dash in R?

the hyphen-minus (-, ASCII 45, next to the zero key) the en-dash (–, Unicode 2013, Alt+0151 on Windows) the em-dash (—, Unicode 2014, Alt+0150 on Windows)

How to type minus hyphen?

Pressing the - on your keyboard, usually next to the 0 (zero) key, will produce a hyphen-minus.

What is the minus sign called?

Definition of minus sign : a sign − used in mathematics to indicate subtraction (as in 8−6=2) or a negative quantity (as in −10°) — called also negative sign.


1 Answers

Try backticks around CES-D:

qplot(1:10, 1:10) + labs(x = expression(sqrt(`CES-D`~scores)), y = "CES-D scores")
like image 83
neilfws Avatar answered Sep 27 '22 21:09

neilfws