Plotting multiple lines gives error: discrete value supplied to continuous scale

Hi, this is probably extremely basic, but any help would be much appreciated. The main problem I get is Error: Discrete value supplied to continuous scale. My dataset is called Vekt and I want to be able to create multiple lines on the Y axis similar to this in R:


This is my script so far:

Vekt <- read.xlsx("../data/Vekt.xlsx")
ggplot(data = Vekt, aes(x = Week, y = Fresh)) + geom_line()
ggplot(Vekt, aes(x = Week)) + geom_line(aes(y = Fresh), color = "darkred") + geom_line(aes(y = Frozen), color = "steelblue", linetype = "twodash"). 

Using the economics dataset in ggplot leaves me with no issues, which leads me to believe that there's something wrong with how I've imported the dataset.

> head(Vekt)
  Week Fresh Frozen
1    1  3728    383
2    2  4054    216
3    3  4043    633
4    4  3730    393
5    5  3831    453
6    6  4415    265

The dataset contains information of frozen and fresh food exported since 2000 in ton which is 1028 weeks for context.

I realize this is probably a terrible explanation but any help is appreciated!

The first thing I would do, given the error you are seeing, is run the command


and see if the Week column is a number or character or a factor. I suspect something in the spreadsheet has caused R to interpret the column as character. Excel allows columns with mixtures of numbers and characters and R does not.

You are absolutely right! Right now Week and Fresh are shown as num and frozen is Chr.

Is there a simple way of changing this? I've tried Frozen <- as.numeric() but I'm probably missing something obvious here.

My advice is to look for the values in Frozen that contain whatever it is preventing the column from being interpreted as numeric. In your example data, the values of Frozen are integers. If that is generally true, then

NonNum <- grepl("\\D", Vekt$Frozen)
BadRows <- Vekt[NonNum, ]

will give you a data frame with the rows that have non numeric characters. If there are decimal numbers or scientific notation, the problem is more difficult.