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:
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.
The first thing I would do, given the error you are seeing, is run the command
str(Vekt)
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.
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
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.
Hi again, just a followup question. I've managed to create the line graph, but I changed the data to weeks, and it looks like this. Showing 1028 weeks instead of a select period does not look ideal, but that is the only way so far that did not give me any errors. I was thinking I should create a vector (with the old data that is in years+weeks), something like this: Labels<-c("2003U44", "2007U35", "2011U26", "2015U18", "2019U09").
Is this the right approach (check opening post for how I would like it to look)? Also how do I include it into this script:
When I run a slightly modified version of one of your ggplot() functions, I get an x axis properly labeled with the year and week. Try running the code below and see what you get.
Thanks for your help! Your code does work, but it's not exactly what I'm looking for as it's 5 obs. of 3 variables, and the data I want to use is 1026 obs. of 3 variables. I have been playing around with it a bit and this is the closest I've gotten:
What's happening is that you have those seemingly thick bars at the bottom, which are actually text overlaid (you can see the 2 shape at the bottom left of the x-axis). To set specific breaks (the distance between labels) and labels, you pass breaks and labels argument to one of the ggplot2 functions scale_x_*(). With the scale_x_date() variant, you can set date_breaks, which you can pass units of time like "2 days", or "5 weeks".
There's a nice example of this here (note the relevant part is where scale_x_date() is used).
I think the main problem I'm having is that my data is in year+weeks, and not date format. My x = Week is just a character variable and I can't seem to figure out how to change it in a way that makes sense. I can't change it to specific dates as I don't have that information and it wouldn't make sense. I tried changing it to weeks only, but 1026 weeks doesn't come off as easy to read and whoever is reading it would have to do some math to find out which year a certain point in the line graph would be since the data contains 19 years (2000-2019). Any suggestions?