to label the axis in a ggplot2 in R with the derivative of Q, i need the character "Q with overdot" --> "Q̇"
is there a library or anything to integrate special characters like this?
I could not find a unicode code for Q̇, but you can use expression(dot(Q)), even though the dot may not be centered.
plot.new()
title(main = expression(dot(Q)))
There is no unicode character for Q-dot. An interesting read about that can be found here: http://www.personal.psu.edu/ejp10/blogs/gotunicode/2008/11/glyph-du-jour-thermodynamic-q-.html
Your rescue comes with the expressions, where you can place a single dot on anything.
https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/plotmath.html
It will just place one . on top of the full string provided in the dot()
Some small example on the Stefan-Boltzmann Law
plot.new()
title(main = expression(dot(Q) == epsilon * sigma * A * (T[SURFACE]^4 - T[SURROUNDINGS]^4)))
Related
is there a resource to see R symbols and their meanings? I have tried ?dictionary, but it did not have any results. Since the Help page has words and definitions like
?plot bringing up things like
pch
a vector of plotting characters or symbols: see
(underlined) points.
I thought their might be something similar with symbols in r like
" + ? * ~ %>% | [: "
"plus, question, multiply, ?, ?"
It would help me to verbalize them.
As for the pch in plot(), it is called a parameter. You can find the explanation of the parameters by
?par
As for " + ? * ~ %>% | [: " these are functions. To find their explanations, you can use backticks :
?`+`
?`?`
?`*`
?`~`
?`[`
and so on.
EDIT (to highlight important information in my comment) :
If you want to get a comprehensive explanation of those parameters and symbolic functions, I highly recommend An
Introduction to R by W. N. Venables, D. M. Smith and the R Core Team, available here. Check "Appendix D Function and variable index" to find the page number of any function.
This is a follow up question to "Displaying a greater than or equal sign"
This is the text I wish to display as the y axis label:
Pr(Number of Invasions, X ≥ x)
This is the code:
expression(paste("Pr(Number of Invasions, ", italic('X'), "\u2265", italic('x'), ")"))
What I get is:
Pr(Number of Invasions, X = x)
This is the same result in the thread mentioned above. "\u2265" is supposed to overcome the issue, as suggested in the answers to the thread but it doesn't in my case.
When I run "\u2265" the result is:
"\u2265"
[1] "≥"
When I assign this to an object I get the same result:
symbol<-"\u2265"
symbol
[1] "≥"
However, in the Global Environment the object "symbol" contains "=".
Can anyone suggest how to display the symbol in the plot?
The answer isn't obvious to me.
I'm using RStudio, and OS system is Windows 7
By placing quotations marks around >= or \u2265 within paste within expression, it is was not able to produce the right symbol.
Even though I was formatting the Xs in italics, I should have just treated the code as if it was X>=x, which is what expression really wants to see, as MrFlick suggested... which makes sense now.
So:
expression(paste("Pr(Number of Invasions", italic('X')>=italic('x'), ")"))
Thanks MrFick!
You don't need paste. It's often clearer to use ~ and * as separators
plot(1,1, xlab=expression(Pr*'('*Number~of~Invasions~~ italic(X)*'\u2265'*italic(x)*")") )
That way it's easier to transition to the "full" plotmath version which gets a different spacing and looks better:
plot(1,1,
xlab=expression( Pr*'('*Number~of~Invasions~~ italic(X) >= italic(x)*")" )
)
If you had really wanted to have a named token hold the "≥" character, you can use the bquote and .( )-functions. The names inside the .( ) get evaluated (when the dot-function is within bquote):
symbol<-"\u2265"
plot(1,1,xlab=bquote(Pr*'('*Number~of~Invasions~~ italic(X) * .(symbol) * italic(x)*")") )
I would like to have the title for the plot in two lines, but this does not work, why? and how can I make it work?
CVal<-1
SumEpsVal<-2
plot(1:10, main=bquote(paste("C=", .(CVal), " \n ", sum(xi), "=", .(SumEpsVal) )))
This here works:
plot(1:10, main=paste("C=1", "\n", "SumXi=2"))
I guess bquote makes something wrong... (look up ?bquote)
I tried to change environment in bqoute (the where-argument) but I don't know which environment to take.
BTW:
plot(1:10, main=bquote(paste("C=", .(CVal), "bla \n ", sum(xi), "=", .(SumEpsVal) )))
makes something crazy with the "bla".
Personally I would use mtext as already suggested. But if you really want it to be a one-liner, you can "cheat" bquote by using atop:
plot(1:10, main=
bquote(atop(paste("C=",.(CVal)), paste(sum(xi),"=",.(SumEpsVal)))))
It even aligns both lines neatly to the center.
The root issue is that plotmath does not support newlines within the
expressions to be output.
Control characters (e.g. \n) are not interpreted in character strings in plotmath,
unlike normal plotting.
You really need to create and output each line separately.
For example :
Lines <- list(bquote(paste("C=", .(CVal))),
bquote(paste(sum(xi), "=", .(SumEpsVal))))
Now output each line The text in the list is converted to expressions do.call
mtext(do.call(expression, Lines),side=3,line=0:1)
One way to achieve this is to use mtext to add an additional line under the main title as follows:
plot(1:10, main=bquote(paste("C=", .(CVal))))
mtext(bquote(paste(sum(xi), "=", .(SumEpsVal) )),side=3,line=0)
There may be a prettier solution, but perhaps this is enough for your needs.
I want the pch in the below to show "B -" however it's only showing "B". How do I remedy this?
plot(1:3,pch="B -",xlab="",ylab="")
Help page of function par and argument pch= says that "Either an integer specifying a symbol or a single character to be used as the default in plotting points". So only first letter is used as symbol.
You could use function text() instead to get all symbols.
plot(1:3,type="n",xlab="",ylab="")
text(1:3,"B -")
I wish to include a subscript and a title running into two lines at the same time but am not getting desired result with following commands:
base<-'B1'
compare<-'A1'
plot (1, 1, main = bquote('Annual mean' ~CO[2] ~'Flux Difference: \n' ~.(compare)~ 'minus'~.(base)))
I wish to insert a line break after 'Flux Difference' but its not happening instead this term is hanging nowhere. Please help me.
Thanks,
Munish
This is a fairly common request and there is no really clean answer. Plotmath will not accept a "\n" (and the help page documents this.) One dodge is to use each line as an argument to the plotmath function atop. The other plotmath trick sometimes of use is phantom with an empty argument list to allow the tilde not to throw an error, but that is not needed here:
plot (1, 1, main = bquote( atop('Annual mean' ~CO[2] ~'Flux Difference:' ,
.(compare)~ 'minus'~.(base))) )