Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab03 first chunk #15

Open
daliahamooda opened this issue Sep 12, 2020 · 1 comment
Open

Lab03 first chunk #15

daliahamooda opened this issue Sep 12, 2020 · 1 comment
Labels

Comments

@daliahamooda
Copy link

when i am trying to code the first chunk as plot.new()

plot.window(xlim = c(1900, 2012),
ylim = c(ave.so.min,
ave.so.max))
points(x = year,
y = ave.so,
col = "gray85",
pch = 16,
cex = 0.75)

, I find this msg "error in xy.coords(x, y) : 'x' and 'y' lengths differ"

I am not sure what is wrong ? Can you help please?

@jamisoncrawford
Copy link
Collaborator

Hi @daliahamooda. The following error:

error in xy.coords(x, y) : 'x' and 'y' lengths differ

...means that you've specified a different number of values for x coordinates and y coordinates.

When we create a scatter plot with points(), each data point has a pair of values:

  • The x coordinate
  • The y coordinate

When x and y are use together, they can be plotted along an x- and y-axis, or a "Cartesian plane".

When you supply multiple coordinate values for x, you must supply the same number of coordinate values for y.

plot(x = 1:10, 
     y = 11:20)

image

However, if you only provide, e.g., 5 coordinate values for x and 6 coordinate values for y, it results in an error because there is a sixth y coordinate value with no matching or paired x coordinate value.

In your call to points(), your y = argument is specified as ave.so and your x = argument specifies year, so this means that you either have more values for average league strikeouts than total years, or more total years than values for average league strikeouts, and they do not make equal x-y coordinate pairs.

Try this to determine the number of values in each object:

length(year)
length(ave.so)

It's likely that earlier in your script you did something to change the values in these objects so that they are no longer equal, like filtering or subsetting. I cannot tell you more without seeing those parts of the script.

Let me know if this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants