2

I read a table. Put the columns names into it. Then I and then Plot the graph with the help of GGplot. I gets error when in aes parameter in ggplot I use names with a space in between like " shucked weight" as shown in code but the code runs and graph is plotted if I use single letter parameter like "wweight". When I replaced column name of "shucked weight" to "sweight" , I got the graph without an error.

This is quite unusual error that I have noticed and I am not able to figure out why?

library(data.table)
a<-fread("https://archive.ics.uci.edu/ml/machine-learning-databases/abalone/abalone.data",sep=",")
dim(a)
names(a)<-c("sex","length","diameter","height","wweight","shucked weight","viscera Weight","shell weight","rings")
g<-ggplot(data = a,aes(wweight,rings))
g+geom_point()+geom_smooth(method="lm")
g<-ggplot(data = a,aes(shucked weight,rings))
g+geom_point()+geom_smooth(method="lm")

Error statement after Execution :

Error: unexpected symbol in "g<-ggplot(data = a,aes(shucked weight"
1
  • 3
    If you use names with spaces in them, you need to surround them with backticks (`) so R knows it's one symbol. Better, don't use variable names with spaces in them. See ?Quotes. Commented Jul 26, 2016 at 6:07

1 Answer 1

2

Answered in comments:

If variable names include spaces or other special characters you need to surround them with backticks:

g <-ggplot(data = a, aes(`shucked weight`, rings)) + 
    geom_point() + 
    geom_smooth(method = "lm")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.