I tried searching, but this bothers me quite a bit, as it in my opinion should be a simple line of coding. However, i keep getting an error when trying...
Firstly, this code works fine
scale_linetype_manual("",
values=c("pAl"=4,"pAlOH"=3, "pAl7OH17"=6, "pAl13OH34"=2,"pAlOH4"=1,"pAl2OH2"=5),
labels = c(expression("Al"^"3+"),
expression("Al(OH)"^"2+"),
expression("Al7(OH)"[17]^"4+"),
expression("Al13(OH)"[34]^"5+"),
expression("Al(OH)"[4]^"-"),
expression("Al2(OH)"[2]^"4+")))+
I do, however, want some of the numbers after Al to be subscripted too, but when trying
expression("Al"[2]"(OH)"^"2+") or expression("Al" ~ [2] ~ "(OH)" ~ ^ ~ "2+")
or whatever variant i can come up with, i keep getting an error.
Again, there's probably an easy fix. Sorry for my lack of experience in using R :)
library(grid)
e <- c("Al[2]~(OH)^'2+'",
"Al[7]~(OH)[17]^'4+'")
grid.newpage()
grid.text(parse(text=e), y=c(0.4,0.6))
Related
I was trying to do a QCA analysis of sufficeny in RStudio 4.1.3. using truthTable command. By running the code i get Error: wrong outcome specification. The outcome is written correctly. When I do an analysis of necessity with superSubset code everything works fine. Everything is coded numeric but it does not work with bivariate callibration either.
> ttCO21 <- truthTable( data = mydata, outcome = "CO21",
+ conditions = "GENDG1, FDI1, GDP1",
+ sort.by="incl, n", show.cases = TRUE, complete = TRUE)
**Error: Incorrect outcome specification.**
I had the same issue today and the solution was to delete any unnecessary columns (or create a new dataframe). I left only the calibrated conditions and outcome, because when I found this error, the raw data was in the same df, even if was not using it in the truthTable() command.
Because of the 3 hours i wasted on this problem i'll share my situation and solution. I had the exact same problem. creating a new df did not help, nor did removing unnecessary colums (wouldn't make sense anyway). Completely reinstalling en reloading the QCA package did work for me. Hope this helps someone.
you can try "comma" instead of "dot" (in “decimal") when you import file
In the book Machine learning for hackers Chapter4, there is a line of code contains ddply which is:
from.weight<-ddply(priority.train,.(From.EMail),summarize,Freq=length(Subject))
and it doesn't work.I have seen somewhere else saying that we can get the same result by changing the code to:
from.weight <- melt(with(priority.train, table(From.EMail)), value.name="Freq")
from.weight <- from.weight[with(from.weight, order(Freq)), ]
Is there any possibility that we still use ddply and make it?
I have been getting the error Error in default + theme : non-numeric argument to binary operator. I have been using R and teaching R for a long time but I can't find this problem. I have included a reproducible example that fails this way below:
library(tibble)
library(ggplot2)
brains <- as_tibble(brains)
brains <- brains[1:10, ]
brains
ggplot(brains, aes(x = BodyWt, y = BrainWt)) +
geom_point()
The error occurs when executing the ggplot() statement.
My hardware is an HP Laptop 15-ef0xxx. I am running Windows 10 Home version 2004. I am running RStudio community edition "Water Lily" and R version R x64** 4.0.2.
I know this is a simple error and it is driving me crazy.
So I finally solved this problem. On the github issue I had opened Hiroaki commented that "One possibility is that you might set a invalid default theme in your .Rprofile, but I'm not sure..." (see link to issue below).
I'm not sure if your R file is part of a project but mine is.
So I went back and deleted the theme_set() line in my R file, went in and double checked all my project options and selected the option "Disable .Rprofile execution on session start/resume" and "Quit child processes on exit". And then I restarted the R session and now everything works. Including on the default R editor console.
I'm not sure if all those steps are necessary but that seemed to do the trick for me! Hope it helps.
I thought this was an RStudio issue but it seems it's possibly a ggplot2 > problem. I have verified using two different datasets that the same >error comes up when I try using ggplot2 in RStudio or using the default R >console. I get the exact same error with code that's been working fine >but now suddenly won't. I have opened an issue on Github (ggplot2) with a >reprex. Might be worth checking there: >https://github.com/tidyverse/ggplot2/issues/4177
I know this is not an answer per se but I don't have enough reputation >points to add a comment to the previous answer but I thought linking to >the issue on Github might help.
I think you have numbers quoted somewhere and you are trying to perform mathematical operation on character values. Consider
x <- c("5","6")
y <- x/1
> y <- x/1
Error in x/1 : non-numeric argument to binary operator
Now try converting x to numeric and perform the same operation.
y <- as.numeric(x)/1
> y
[1] 5 6
So, you need to use as.numeric on your variable.
The following should resove this issue
ggplot(brains, aes(x = as.numeric(BodyWt), y = as.numeric(BrainWt)))
apologies for the trivial nature of this question. I have searched for other instances of this and can't find any.
I am trying to combine the expression() function with paste(), for example to do: expression(paste("TNF", alpha))
But everytime I enter a command using expression() I just get my command returned to me, so the above command just prints:
expression(paste("TNF", alpha))
What am I doing wrong?
Ah ok I had misinterpreted the function ofexpression() and it seems it's interpreted the way I wanted it to be within the scale_x_discreet() call when building my plot in ggplot2.
In case it's useful to anyone else, my code became (where a is a ggplot object):
a + scale_x_discrete(labels=c("Vehicle", expression(paste("TNF", alpha))))
Which then produced a group label of "TNFα".
To try and get to grips with data manipulations in R, I've started reading Hadley's paper on split-apply-combine.
I'm on page 3 and trying to go through the code to understand it. Unfortunately the code is erroring and my reproduction is faithful (I've done c&p and handtyped). As I'm trying to learn this stuff and I'm right at the beginning I can't actually tell what's wrong with it. I tried it on both R2.5 and R3.0
library("MASS")
library("plyr")
data(ozone)
one<-ozone[1,1,]
month<-ordered(rep(1:12,length=72))
model<-rlm(one ~ month - 1)
deseas<-resid(model)
deseasf<-function(value) {rlm(value ~ month - 1)}
models<-aaply(ozone,1:2,deseasf)
deseas<-aaply(models,1:2,resid)
Where the models line errors with Error: Results must have one or more dimensions.
Can somebody tell me whether it works for them, or what needs to be fixed/amended if it doesn't and why?
PS - Can't check on http://plyr.had.co.nz/ for errata because my work proxy currently blocks the site!
It should be
models <- alply(ozone, 1:2, deseasf)
deseas <- ldply(models, resid)
It turns out this is a bug in aaply and Hadley has said he will look into it soon:
https://groups.google.com/forum/#!topic/manipulatr/kg2wDU96mGM