 # How to deal with unequal amounts of the X, and Y variables in ggplot graphs

I am attempting to make a scatter plot in ggplot with the variable "year" as the x axis and the variable "gdp" as the y axis. However, these two variables are not of equal length. I tried to fix this by omitting NA values but the lengths are still different. How do I proceed/equalize the length of each variable so that the plot can be made? Thanks in advance

``````mutate(nations,gdp=(gdp_percap*population)/1,000,000,000,000)
gdp
``````

ggplot(na.omit(nations), aes(x= year, y = gdp)) +
geom_point()

Error: Aesthetics must be either length 1 or the same as the data (4303): y

Is that calculation really working ? I would think that the commas would mess it up.
Perhaps you should see if you get a different data if you use

``mutate(nations,gdp=(gdp_percap*population)/1000000000000)``

When you say the variables are not of equal length, do you mean values are missing from some data points? I don't quite understand what you mean by different in length.

"Error: Aesthetics must be either length 1 or the same as the data (4303): y"
Im referring to the above error message

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

@andresrcs Thank you for this guide, I'll take a look at it asap

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

Just changed that, thanks

Hi @Ness329,
Your `nations` dataframe should have 4 columns (all the same length, by definition in a dataframe) named: `year, gdp_percap, population, gdp`. Is that correct?
You could post the output from

``````head(nations, n=20)
``````

so we can see what your data looks like, and then work out why ggplot is complaining.
HTH Hi @DavoWW there are actually 10 columns, could this be the reason for the issue?