I am trying to use ggplot2
to plot multiple lines in one R plot but I have a problem and I am not able to. This is my first question here. I am learning how to use R studio and its package so I don't know it very well so please be patient. This is the code I wrote:
library(ggplot2)
x <- 1:10
y1 <- dati.m$With.no.educational.qualifications
y2 <- dati.m$Compulsory.education..1st.cycle
y3 <- dati.m$Compulsory.education..2nd.cycle
y4 <- dati.m$Compulsory.education..3rd.cycle
y5 <- dati.m$Upper.secondary.education
y6 <- dati.m$Higher.education
df <- dati.m(x, y1, y2, y3, y4, y5, y6)
ggplot(df, aes(x)) +
geom_line(aes(y=y1),
colour="red") +
geom_line(aes(y=y2),
colour="green") +
geom_line(aes(y=y3),
colour="blue") +
geom_line(aes(y=y4),
colour="yellow") +
geom_line(aes(y=y5),
colour="orange") +
geom_line(aes(y=y6),
colour="black")
but when I execute it R, I get an error:
Error: Aesthetics must be either length 1 or the same as the data (17): y, x