I have been trying to do a plot with 2 lines using ggplot, but it says the following: "Aesthetics must be either length 1 or the same as the data (1): x and y".
Here's the dataset I am using: unvoting <- read.csv ("https://raw.githubusercontent.com/umbertomig/intro-prob-stat-FGV/master/datasets/unvoting.csv")
Here's the question: "Examine how the median ideal points of Soviet/post-Soviet countries and all other countries have varied over all the years in the data. Plot these median ideal points by year."
Here's the code that I used so far:
pst_svt <- subset(unvoting, svtunion == 1)
othr_cts <- subset(unvoting, svtunion == 0)
y1 <- tapply(othr_cts$idealpoint, othr_cts$Year, median)
y2 <- tapply(pst_svt$idealpoint,pst_svt$Year, median)
ggplot(pst_svt) +
geom_line(aes(x= Year, y= y1, color="Other Countries")) +
geom_line(aes(x= Year, y=y2, col="Other Countries")) +
scale_color_discrete(name="Legend") +
labs(title="Variation of Median Ideal Points")


svtunionis not in that dataset.svtunioncolumn that you're subsetting by?pst_svtdata, which contains only 1 record, is incorrect.