Error: Aesthetics must be either length 1 or the same as the data (20): x

Thanks for helping me!

Here is my code.

norm1<-data.frame(rnorm(20,0,1))
library(ggplot2)
ggplot(data=data.frame(norm1),aes(x))+
geom_histogram(color="white",fill="pink",alpha=0.5,bins=20)

norm1<-data.frame(rnorm(20,0,1))
library(ggplot2)
ggplot(data=data.frame(norm1),aes(x))+

  • geom_histogram(color="white",fill="pink",alpha=0.5,bins=20)
    Error: Aesthetics must be either length 1 or the same as the data (20): x

You did not define the column names in your dataframe, therefor ggplot was not able to find the correct data.
This works:
norm1<-data.frame(x = rnorm(20,0,1))

It works!
Thank you so much!!:laughing::laughing:
You are so kind.:blush:

Maybe you can mark the topic as solved, so others know they don't have to click on it anymore?

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.