Reputation: 1
I am trying to create a ggplot using this code.
df <- read.csv("2019.csv", header = TRUE, sep = "," )
head(data)
ggplot(data = df, aes(x = 'GDP.per.capita', y = 'Social.support')) +
geom_line(color = "red", size = 1) +
geom_point(size = 2)
but on the console i'm getting a warning message
1: In geom_line(color = "red", size = 1) :
All aesthetics have length 1, but the data has 156 rows.
ℹ Please consider using `annotate()` or provide this layer with data containing a single
row.
2: In geom_point(size = 2) :
All aesthetics have length 1, but the data has 156 rows.
ℹ Please consider using `annotate()` or provide this layer with data containing a single
row.
Went to YT but everyone was doing the same thing I'm doing. they are not getting any message but I'm getting this message.
Upvotes: 0
Views: 65
Reputation: 226712
You shouldn't put your variables to be plotted in quotation marks.
This works fine:
ggplot(data = mtcars, aes(x = mpg, y = hp)) + geom_point()
This gives a warning like the one you're seeing (and a plot that is junk):
ggplot(data = mtcars, aes(x = 'mpg', y = 'hp')) + geom_point()
Warning message: In geom_point() : All aesthetics have length 1, but the data has 32 rows. ℹ Please consider using
annotate()
or provide this layer with data containing a single row.
Upvotes: 1