I'm trying to write the << symbol in R but I'm not succeeding. Any tips?
plot(expression(alpha<1))
plot(expression(alpha<<1))
Error: unexpected input in "plot(expression(alpha<<"
Using unicode
plot(1, 1, xlab = bquote(alpha~"\u226A"~1))
This is the closest I am so far, how does this work for you?
plot(
x = 1:10,
y = 1:10,
main = expression(paste(alpha, "<<", 1))
)
Related
I try to use ggscatter() function from ggpubr package with the following code
ggscatter(mtcars,
x = "hp", y = "carb",
cor.coef = TRUE, cor.method = "spearman",
xlab = "x1", ylab = "x2")
but I get the following error.
Error in parse(text = text[[i]]) : :1:16: unexpected ','
1: italic(R)~=~0,
Thanks in advance for the help.
Not sure about your question as your code is working fine.
Sample data:
data(mtcars)
Sample code:
library(ggpubr)
ggscatter(mtcars,
x = "hp", y = "carb",
cor.coef = TRUE, cor.method = "spearman",
xlab = "x1", ylab = "x2")
Plot:
I think the most likely answer to your problem is that you have set your output decimal to a comma with options(OutDec = ",")
I had the exact same problem. Here is my question with the following answer: Error in parse(text ...) unexpected comma "," when plotting ggplot with ggpubr::stat_cor and output decimal set to comma (options(OutDec = ","))
This is a bug in the package ggpubr as it cannot handle commas as
decimal seperators. For more information see here or in the comments:
MrFlick: Specifically I think it's in this line
https://github.com/kassambara/ggpubr/blob/ac5a01f586a5f0b47260fed071e79be36ef3f8ea/R/stat_cor.R#L207
. Those values should be wrapped in quotes to prevent the parsing
error. And the problem with the persistent decimal point in the
p-values comes from
https://github.com/kassambara/ggpubr/blob/ac5a01f586a5f0b47260fed071e79be36ef3f8ea/R/stat_cor.R#L219
. It doesn't look like the package really support a comma separator. –
However, there is a workaround (pointed out by #MrFlick) by passing the argument , output.type="text" in the stat_cor function e.g.:
stat_cor(show.legend = F ,label.y = c(18), method = "pearson",
output.type="text") However, there is an edge case where this does not
work, if p < 2.2e-16 (as with the example data) as the value of p is
passed as a string and not a number. Otherwise it works though.
I am trying to add a subscript to a ggpubr graph, which I found that I can do quite easily using parse and a set of square brackets. However, the problem is that within the axis label, I have a second set of square brackets that should be in regular type. Something like this:
library(ggpubr)
cars$speed <- log10(cars$speed)
ggscatter(cars, y = "speed", x = "dist", ylab = parse(text = "log[10](speed [μm])"))
I want the base of the logarithm (10) in subscript, but not the distance measure, [μm], which should keep it's brackets and stay in normal font size.
I have tried using paste(parse(text = "log[10]"), "(speed [μm])"), parse(text = "log[10](speed \\[μm\\]") and expression, but these have not worked for me so far.
Alternatively use expression...
ggscatter(cars, y = "speed", x = "dist", ylab = expression(log[10]*"(speed [µm])"))
Created on 2022-03-03 by the reprex package (v2.0.1)
You could do:
ggscatter(cars, y = "speed", x = "dist", ylab =
parse(text = "paste(log[10], \"(speed [μm])\")"))
x<-seq(-2*pi,2*pi) #range of x
f<-(2*(abs(sin(x)))+(1/2))
f1<-function(x)(2*(abs(sin(x)))+(1/2))
x1=seq(-2*pi,-pi)
g<-2*cos(x1)
gun<- function(y) 2*cos(x1)
curve(gun, from=-2*pi, to=-pi, type='l')
So, I want to plot these functions in the same graph but I get an error when I try to plot g:
Error in curve(gun, from = -2 * pi, to = -pi, type = "l") :
'expr' did not evaluate to an object of length 'n'
I am not sure how to fix this, I've seen people use Vectorize() but it doesn't seem to help.
Any advices?
You are calling data stored in your environment in your function. It should be referencing the data that is passed into it.
x<-seq(-2*pi,2*pi) #range of x
f<-(2*(abs(sin(x)))+(1/2))
f1<-function(x)(2*(abs(sin(x)))+(1/2))
g<-2*cos(x1)
gun<- function(y) 2*cos(y)
curve(gun, from=-2*pi, to=2*pi, type='l')
to add the second function to the plot you can run this
curve(f1, from = -2*pi, to = 2*pi, type = 'l', col = "red", add = TRUE)
I coulnd't found any post with a related subject. I actually don't know if its posible.
So I have my. csv file:
Periodo;Teorico;Real;F1;F2;F3
20140101;50;20;7;7;16
20140108;55;29;11;5;5
20140115;52;21,4;8,6;10;12
20140122;66;32;9;8;17
I asign it to a data.frame:
df<-read.csv2('d:\\xxx\\test2.csv', header = T, sep = ";")
Then I do barplot function:
bp <- barplot(t(df[,-c(1:2)]),col=c("blue", "red", "green", "yellow"),legend=colnames(df[,-c(1:2)]),args.legend = list(x="topleft"))
axis(side = 1, at = bp, labels = df$Periodo)
title(main = "Teorico = Real + F1+F2+F3", font.main = 4)
Now I must calculate the following function: (efficiency function)
((Teorico-Real)/Teorico)*100
And represent the result of the function of each row on the top of each Periodo (week).
If you could help me with the code for the function and "replotting" parts or give some guidelines or posts related to this I would be really gratefull.
Thanks
You can try:
lbls <- round(((df$Teorico - df$Real) / df$Teorico)* 100)
mtext(lbls, at=bp)
(I just used round to make it look better.)
The R package diagram has been giving me some very nice flow charts. Here is a simple example:
install.packages("diagram")
require(diagram)
A = matrix(nrow = 2, ncol = 2, data = 0)
A[2,1] = "hello"
par(xpd = NA)
plotmat(A, name = c("A", "B"))
I would like to change the arrowlabel (currently set as "hello") to be "(+)". So,
A[2,1] = "(+)"
plotmat(A, name = c("A", "B"))
But this fails:
Error in parse(text = x, ...) : <text>:1:3: unexpected ')'
1: (+)
^
Is there a set of escape characters, or some other trick, that will force parse to interpret my symbols as simple text? Of course, a workaround is to use text to place text on the plot, but I'm hoping to take advantage of plotmat's built-in label positioning functionality.
Try
A[2,1] = "`(+)`"
plotmat(A, name = c("A", "B"))