# Plot error - x and y lengths differ

Hello,

I have been trying to make the following plot:

plot(formerussrcountries2\$Year,
tapply(formerussrcountries2\$Year, formerussrcountries2\$idealpoint, median),
xlab = "Year",
ylab = "ideal points")

But it gives me the following message:

Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ

Is there any way I can solve this problem?

Thank you.

Can you provide a reproducible example so that we can see your datasets?

Suggest you calculate the median first, outside the plot function.

I'm sorry, I will be writing them bellow.

The dataset I'm using is:

Then, I have to create a vector with the former USSR countries:

formerussrcountries <- c("Estonia","Latvia","Lithuania","Belarus","Moldova","Ukraine","Armenia","Azerbaijan","Georgia","Kazakhstan","Kyrgyzstan","Tajikistan","Turkmenistan","Uzbekistan","Russia")

After that, I have to examine how the median ideal points of Soviet/post-Soviet countries and all other countries have varied over all the years in the data. For that, I have to plot these median ideal points by year.

These are the codes I'm writing, but when I run the plot, it says that my x and y leghts differ.

formerussrcountries2 <- filter (unvoting, formerussrcountries == 1)

restofthecountries <- filter (unvoting, formerussrcountries == 0)

tapply(formerussrcountries\$idealpoint, formerussrcountries\$Year, median)

tapply(restofthecountries\$idealpoint, restofthecountries\$Year, median)

plot(formerussrcountries2\$Year,
tapply(formerussrcountries2\$Year, formerussrcountries2\$idealpoint, median),
xlab = "Year",
ylab = "ideal points")

lines(formerussrcountries2\$Year,
tapply(restofthecountries\$idealpoint, restofthecountries\$Year, median))

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