DS4PS / cpp-526-fall-2020

Course shell for CPP 526 Foundations of Data Science I for Fall 2020
http://ds4ps.org/cpp-526-fall-2020/
MIT License
3 stars 1 forks source link

Lab03 first chunk #15

Open daliahamooda opened 4 years ago

daliahamooda commented 4 years ago

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 commented 4 years ago

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:

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!