# R Error in xy.coords: x and y length differ (2 Examples)

In this R tutorial you’ll learn how to handle the Error in xy.coords that ‘x’ and ‘y’ lengths differ.

## Creation of Example Data

my_x <- 5:8 # Create example data my_y <- 5:9 |

my_x <- 5:8 # Create example data my_y <- 5:9

## Example 1: Replicating the Error Message – ‘x’ and ‘y’ lengths differ

plot(my_x, my_y) # Plotting doesn't work due to length difference # Error in xy.coords(x, y, xlabel, ylabel, log) : # 'x' and 'y' lengths differ |

plot(my_x, my_y) # Plotting doesn't work due to length difference # Error in xy.coords(x, y, xlabel, ylabel, log) : # 'x' and 'y' lengths differ

## Example 2: Solving the Error Message – ‘x’ and ‘y’ lengths differ

my_y_short <- my_y[1:length(my_x)] # Harmonize length of x and y |

my_y_short <- my_y[1:length(my_x)] # Harmonize length of x and y

plot(my_x, my_y_short) # Properly draw plot |

plot(my_x, my_y_short) # Properly draw plot