HertieDataScience / SyllabusAndLectures

Hertie School of Governance Introduction to Collaborative Social Science Data Analysis
MIT License
37 stars 60 forks source link

Unresolved problem creating a plot in R Studio #36

Closed mr-r0b0t closed 8 years ago

mr-r0b0t commented 8 years ago

Hi everyone,

I'm wrapping my head around this problem creating a plot and a specific error message that I can't find a solution to... Maybe someone has an idea or can tell me if I'm doing something wrong.

Every time I want to create a plot for our first assignment with the following code

plot(trees$Height, trees$Volume, main='Height and Volume of Black Cherry Trees', xlab='Height in ft', ylab='Volume in cubic ft')

I get the following error message:

ylab='Volume in cubic ft') Error: unexpected ')' in "ylab='Volume in cubic ft')"

According to our slides and the Internet this should be the right way to write the code (in terms of closing the command with the bracket at the end. But somehow R Studio doesn't like it the way I write it here.

Does anyone have an idea?

Thanks a lot!

mcallaghan commented 8 years ago

Curious!

Did you try it with all the arguments on one line? Mysteriously that works, but it doesn't when the arguments are on different lines. I've never encountered that before, and didn't think that was supposed to happen.

The equivalent function in ggplot2 works across lines for example:

ggplot2::qplot(
  trees$Height,
  trees$Volume,
  main="Height and Volume of Black Cherry Trees",
  xlab="Height in ft", 
  ylab="Volume in cubic ft"
)
christophergandrud commented 8 years ago

Hu, both the base R and @mcallaghan's ggplot2 code works for me.

@mr-r0b0t my guess is that there may be something else in your code beyond this call that breaks it. Can you provide a link to your source code file?

mr-r0b0t commented 8 years ago

It's kind of strange, yes... But thanks for your help!

Here's the link to the source code file: https://github.com/mr-r0b0t/hello-world/blob/master/Code_Assignment1_Preview

christophergandrud commented 8 years ago

Not sure if this is entirely it, but on line 33 you are missing a comma after Girth.

The code seems to run without errors after this: a general lesson is that sometimes it is worth looking for earlier errors or warnings as these might create problems that cascade down through your code.