Hi im a real self teaching R newbie:
I'm following a GWR tutorial here
but already on first page my code fails at
colours = c(“dark blue”, “blue”, “red”, “dark red”)
Creates a colour palette and at spplot
spplot(map, “Nocars”, cuts=quantile(Nocars), col.regions=colours)
Error: unexpected input in "colours = c(�"
and the same for spplot
Error: unexpected input in "spplot(Nocars, �"
Could you please help, im sure its something silly.
Related
I am very much a novice with R and am attempting to run a script that will filter a set of SNPs for 6 populations. I've successfully run this script before but I'm getting a new error in the initial stages of the script.
I've not been able to find anything similar to my issue online, though a few have the same error. The error comes up when R is trying to read in the SNP data and the function and error are as follows from the console screen:
>FijiHomaGL <- gl.read.dart(filename = "genCSV_modified.csv", ind.metafile = "COV_file.csv",
+ nas = "-", topskip = 6, lastmetric = TRUE, probar = TRUE)
Starting gl.read.dart
Starting utils.read.dart
Reading in the SNP data
Error in FUN(X[[i]], ...) :
only defined on a data frame with all numeric variables
A screenshot of the .csv file I'm trying to run
I'm not able to include the actual file but a screenshot is linked above for a general idea of the layout.
Any help is much appreciated I am very new so let me know if there is anything else I should include! Thanks in advance. The package being used for this function is dartR but I can't add it as a tag.
This is the end goal however when trying to plot the code below
plot(PCAloadings[,1:2], arrows(0,0,PCAloadings[,1],PCAloadings[,2]), text(PCAloadings[,1:2], labels=rownames(PCAloadings))
I recieve the following error:
in text.default(PCAloadings[, 1:2], labels = rownames(PCAloadings)) : plot.new has not been called yet
I am unsure how to resolve this issue or what it pertains to, any help is welcome.
EDIT: when trying to run line by line only the first line runs. When trying to run arrows or text lines I run into the same error
plot(PCAloadings[,1], PCAloadings[,2])
This is the output from the first line alone
Seems to be a syntax problem. Try
plot(PCAloadings[,1:2])
arrows(0,0,PCAloadings[,1],PCAloadings[,2])
text(PCAloadings[,1:2], labels=rownames(PCAloadings))
I found this error when I was dealing with the swirl assignment:
You're probably sick of it but rerun qplot again, this time with 4 arguments. The first 3 are the same as the last qplot command you just ran (price, data set equal to diamonds, and binwidth set equal to 18497/30). (Use the up arrow to save yourself some typing.) The fourth argument is fill set equal to cut. The shape of the histogram will be familiar, but it will be more colorful.
qplot(price, data = diamonds, binwidth = 18497/30, fill = cut)
Error in readRDS(nsInfoFilePath) : error reading from connection
I cannot solve this problem even after a long search on the internet
I encountered the same error while using ggplot2, even with very simple data and graph.
I traced the readRDS function with the following code :
trace(readRDS, quote(print(ls.str())))
which after running the ggplot code returned something like :
Tracing readRDS(metapath) on entry
file : chr "/home/username/R/x86_64-pc-linux-gnu-library/4.1/farver/Meta/package.rds"
refhook : NULL
I reinstalled the farver package, the error disappeared and I was finally able to plot the graph I wanted.
This package (and the package.rds file) was probably not installed correctly.
I found a similar issue and the tracing command here.
I'm trying to run this code to stretch the axes after creating a matrix based on calculated Euclidean distances:
ds_newA <- sqrt((new[1] -A[1]ˆ2 + (3*(new[2]-A[2]))ˆ2)
However, I'm getting an input error in the R console:
Error: unexpected input in "ds_newA <- sqrt((new[1] -A[1])ˆ"
Error: unexpected input in "ds_newB <- sqrt((new[1] -B[1])ˆ"
How should the code for formatted?
As noticed in the SO thread Error: unexpected symbol/input/string constant/numeric constant/SPECIAL in my code :
These errors mean that the R code you are trying to run or source is not syntactically correct. That is, you have a typo.
To fix the problem, read the error message carefully. The code provided in the error message shows where R thinks that the problem is. Find that line in your original code, and look for the typo.
Most probably, here this is due to the symbol ˆ you are using, which is not the appropriate one for an exponent ^:
# correct symbol ^:
> 2^2
[1] 4
# wrong symbol you seem to use ˆ :
> 2ˆ2
Error: unexpected input in "2ˆ"
Change it to the correct one ^ and you will be fine.
I got this R code to make visualization using ggplot. However, I am getting the problem with syntax. Can anyone see where it went wrong? Thanks!
t <- ggplot_build(p)$data[[3]]
s[i,1] <- as.character(a[i])
s[i,2] <- t[1,2] - t[(length(t[,1])),2]
The error is related to t in this three lines of code.