1

I get the following error using geom_histogram() in ggplot2. Below it is reproduced with standard example data from R, but this seems to happen with any data I provide. I was unable to find explanations and I was unable to debug up through the origin of the error. Any guess? I am using RStudio Version 1.4.1106.

ggplot(diamonds, aes(x=carat)) + geom_histogram(bins=30) 
Error in unit(unclass(x), attr(x, "unit"), attr(x, "data")) : 
  Invalid unit
6
  • May you provide a snippet of your data? Commented Aug 23, 2021 at 15:54
  • 1
    Can't reproduce on macOs R v4.1.1. Commented Aug 23, 2021 at 15:54
  • @mikebader the "diamonds" dataset is included by default in R. Commented Aug 23, 2021 at 15:55
  • Oops, sorry! Do you have any other libraries loaded? Commented Aug 23, 2021 at 16:01
  • 1
    Here, it works. Windows, R version 4.0.5 (2021-03-31) -- "Shake and Throw" Commented Aug 23, 2021 at 16:05

1 Answer 1

2

The error arised from the fact the version of ggplot2 installed was older than the R version (I have to install the packages from a local repository, so sometimes they are not updated). Once I installed the lastest version, it disappeared. Thanks to everyone who investigated the issue.

Sign up to request clarification or add additional context in comments.

1 Comment

Feel free to accept this answer to your own question. It makes it easier for people to search for unanswered questions.

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.