Custom pch in plot only respects first letter in string - r

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 -")

Related

Integration of special Characters like Q̇ in R

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)))

Starting axis label with subscript

I am trying to add specific labels to my axes in R. I have read numerous posts indicating to use the expression function and brackets to do this. The label I want to add to my axis starts and ends with a subscript.
plot(1:10, xlab=expression([10]'x'[5])
Starting the label with a subscript results in an error:
Error: unexpected '[' in "plot(1:10, xlab=expression(["
I have attempted to add in empty quotation marks as a form of placeholder, but it doesn't seem to work.
Any help would be appreciated.
You need to separate multiple subscripts with an asterisk (*), and start the expression with an empty string
plot(1:10, xlab=expression(''[10]*'x'[5]))

How to add a space to an object name in R

Piston_Rings<-diameter[1:25,]
I want my quality control graph NOT to have the underscore in the object name.
At the moment there is an underscore (not a hyphen) in that object name. It is possible to construct objects whose names have spaces in them but in order to access them you will then always need to use backticks in order to get the interpreter to understand what you want:
> `Piston Rings` <- list(1,2)
> `Piston Rings`[[1]]
[1] 1
> `Piston Rings`[[2]]
[1] 2
The problem you incur is cluttering up your code, at least relative to obeying the usual conventions in R where a space is a token-ending marker to the parser. Hyphens (at least short-hyphens) are actually minus signs.
If on the other hand you only want to use a modified version of a name that contains an underscore as the title for a graph, then try something like this:
Piston_Rings <- list() # just for testing purposes so there will be an object.
plot( 1:10,10:1, main = sub("_", " ", quote(Piston_Rings)) )
#BondedDust's answer is correct, but (guessing, since you haven't been very specific) a simpler way to get what you want is just to specify xlab or ylab arguments to the plot() function. Let's say you have variables stuff (x) and Piston_Rings (y). If you just
plot(stuff,Piston_Rings)
then the plot will have "Piston_Rings" as the y-axis label. But if you
plot(stuff,Piston_Rings,ylab="Piston Rings")
you'll get the label you want. You can also include lots more information this way:
plot(stuff,Piston_Rings,
xlab="Important stuff (really)",
ylab="Piston Rings (number per segment)")
See ?plot.default for many more options.

How to make the font bold in R's bquote for main of plot?

I make some plots with R and use bquote because I need variables for the main of the plot. However, the main is no longer bold but I want it to be bold. I defined the main as follows:
title = bquote(atop("Empirical Pricing Kernel at Date",~.(EndDate)~"with Index Price"~.(ST)~"€"))
plot(temp, EPK, type="l", main = title)
Enddate contains "2014-08-01" as date and ST is just numeric with 9210.08.
Is there any way to make it bold with or without bquote? I'd like to find a solution with bquote because it's very convenient when using subscripts.
My problem is that I am using it in a par-plot with two plots and the other plot needs no special things in it's main. So, the main is bold. I even tried to just put bquote around it in order to get the same font size but it stayed bold.
I prefer to use what I think of as "pure plotmath" so I use tilde's instead of spaces and use no quotes. I suspect it was the leading tilde in the second argument to bquote that was throwing the error. In plotmath the tildes need something on either side: If you really need a none-displayed something you can always use phantom(0) but why bother in this case?
bquote(atop(Empirical~Pricing~Kernel~at~Date,
bold(.(EndDate))~with~Index~Price~.(ST)~"€"
) )
Test:
EndDate="2014-08-01";ST=9210.08
title = bquote(atop(Empirical~Pricing~Kernel~at~Date, bold(.(EndDate))~with~Index~Price~.(ST)~"€"))
plot(1,1, type="l", main = title)

Using subscript and line break at the same time in plot titles in R

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))) )

Resources