ggplot2 error message

I'm quite new to R studio and ggplot2. Learning to do basic plots on ggplot2.
I've successfully installed and loaded ggplot2 but when I run an argument to produce a plot, it comes up with the following error message. Tried reinstalling the whole programme already! Please help.. Thanks!
ggplot(iris, aes(x=Sepal.Length, y=Petal.Length))
Error in parse(n = -1, file = file, srcfile = NULL, keep.source = FALSE) :
1:1: unexpected $end
Error: unable to load R code in package ‘labeling’

Hi,

Welcome to the RStudio community!

Could you please show me the whole script you are trying to run,including all the packages you load and all code that goes before the line that throws the error. The code should work fine, although the plot won't show anything if you don't tell it to plot points too like this:

library(ggplot2)

ggplot(iris, aes(x=Sepal.Length, y=Petal.Length)) + 
  geom_point()

PJ

Hello pieterjanve,

Thank you. I've copied what is on my console here.

library(ggplot2)

View(iris)
ggplot(iris, aes(x=Sepal.Length, y=Petal.Length)) +

  • geom_point()
    Error in parse(n = -1, file = file, srcfile = NULL, keep.source = FALSE) :
    1:1: unexpected $end
    Error: unable to load R code in package ‘labeling’

I also read some posts on reprex. When I run the argument on reprex this is what it shows

ggplot(iris, aes(x=Sepal.Length, y=Petal.Length)) +
geom_point()
#> Error in ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)): could not find function "ggplot"

Thank you in advance!

This is because you need to include the ggplot2 library in your reprex, as @pieterjanvc did, above:

library(ggplot2)
ggplot(iris, aes(x=Sepal.Length, y=Petal.Length)) + 
  geom_point()
1 Like

Hi Mara,

When I run the whole code (icluding ggplot2) on reprex, it comes up with the following.

library(ggplot2)
ggplot(iris, aes(x=Sepal.Length, y=Petal.Length)) +
geom_point()
#> Error in parse(n = -1, file = file, srcfile = NULL, keep.source = FALSE) :
#> 1:1: unexpected $end
#> Error: unable to load R code in package 'labeling'

I am not sure what to do with it.

Hi Sue: Could you quit, then restart RStudio, and then try executing just this again?

library(ggplot2) 
ggplot(iris, aes(x=Sepal.Length, y=Petal.Length)) + 
  geom_point()

Hi dromano,

Tried that too. Same message pops up.

Hi,

Could you try installing ggplot2 like this:
install.packages('ggplot2', dep = TRUE)
And then re-run the code?

It might help :crossed_fingers:

Thanks, but it comes up with the same error message. I have tried uninstalling R and Rstudio as well but no luck!

A mystery... Could you post screenshots of the left panes of your RStudio window before and after your execute the code, with the console open wide enough to show the error? But first make sure you've re-installed either the tidyverse package or the ggplot2 package as @donbibi129 suggests.

What version of R are you using?
Also just to double check, the iris data is loaded into memory right? Try typing iris in your R Console.
If it throws an error, then try loading it into memory:
data(iris)

If iris was loaded into memory, and the error still persists, then try creating a simple bar plot:

dat <- data.frame(cond = factor(rep(c("A","B"), each=200)), 
                  rating = c(rnorm(200),rnorm(200, mean=.8)))

library(ggplot2)
ggplot(dat, aes(x=rating)) + geom_histogram(binwidth=.5)

And see if ggplot throws any errors.
Kind regards.

This is the screenshot of those panes.

I 'm using R 3.6.2. I tried your way too. Iris is loaded into memory but still the error message pops up. This is the screenshot.

What if you run install.packages('tidyverse', type = 'win.binary') and then try again?

if you run

 packageVersion("labeling")

does it show ?

[1] ‘0.3’

Tried that too.... no luck!

Yes, it does show as above.

thanks Sue, I'm hopeful if we keep looking something will click. Can I ask you to get environment info by sessionInfo() on your console please ?

Thank you. Here is the sessioninfo..

I tried on a different computer and it works fine. So given up on mine. Thank you everyone for your help.