I am trying to create a line chart in R Base where I have two lines. One is for population growth in Oslo and the other one for population growth in Tromso.
However my code only produce one line.
# 1. Read data (comma separated)
res = read.csv2(text = "X-Years;Y-Oslo;Y-Tromso
2017;666757;74541
2018;673469;75638
2019;681071;76000
2020;693556;77000
2021;697057;78000")
# Create Line Chart
# convert factor to numeric for convenience
number_of_x <- length(res[ , 1:1])
# get the range for the x and y axis
x_range <- res[ , 1:1] # Years: 2017 2021
y_range1 <- res[ ,2:2]
y_range2 <- res[ , 3:3]
x_range
y_range1
y_range2
# set up the plot
plot(x_range, y_range1,
type="l",
xlab="Years",
ylab="Population")
lines(x_range, y_range2, type="b")
title("Population Growth")