3

The function scale_y_continuous(expand=c(0,0)) is giving me the error:

Error: Discrete value supplied to continuous scale

I really don't understand what this means. the function is called scale_y_continuous, not scale_y_discrete. Here's my data.

require(ggplot2)  # ggplot
gp <- read.csv("Retail_Gas_Prices.csv")
gp$Date <- as.Date(substr(gp$Date, 1, 10), "%m/%d/%Y")
gp_melted <- melt(gp, id = "Date")

gas_ml_plot <- ggplot(subset(gp_melted, variable != "Weekly.US"), 
               aes(Date, value, colour = variable)) + 
               geom_line() + ggtitle("Retail Gas Prices In The US") + 
               theme(axis.title.x = element_blank()) +
               ylab("Cost in Dollars") + 
               theme(axis.ticks = element_blank()) + 
               labs(colour = "US Region") + 
               scale_color_discrete(labels = c("East Coast", "Midwest", 
               "Gulf Coast", "Rocky Mountain", "West Coast")) + 
               theme(legend.background = element_blank()) + 
               theme(legend.position = c(0, 1)) + 
               theme(legend.justification = c(0, 1)) + 
               scale_y_continuous(expand = c(0, 0)) + 
               scale_x_discrete(expand = c(0, 0))

1 Answer 1

4

The error message is wrong in that the problem is that a Date object was passed to a discrete x scale, not that a discrete value was provided to a continuous scale. The solution is to use the correct x scale; since the x variable is a Date, use scale_x_date(expand = c(0, 0)) in place of scale_x_discrete(expand = c(0, 0)).

I have submitted a bug report describing this problem at https://github.com/hadley/ggplot2/issues/783

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Ista! Can we compile you into some sort of human-code-extension of ggplot2 so that I can get useful errors? :P
Ha ha, @KFunk I can't think of a way to automate it, just keep posting on SO and I'll do my best.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.