3

関数scale_y_continuous(expand=c(0,0))は私にエラーを与えています:

Error: Discrete value supplied to continuous scale

これが何を意味するのか本当にわかりません。関数はscale_y_continuousではなく、と呼ばれscale_y_discreteます。これが私のデータです。

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))
4

1 に答える 1

4

エラーメッセージは、Dateオブジェクトが離散xスケールに渡されたという問題であり、離散値が連続スケールに提供されたという問題ではないという点で間違っています。解決策は、正しいxスケールを使用することです。x変数は日付なので、のscale_x_date(expand = c(0, 0))代わりに使用しscale_x_discrete(expand = c(0, 0))ます。

この問題を説明するバグレポートをhttps://github.com/hadley/ggplot2/issues/783に送信しました

于 2013-03-16T23:54:55.377 に答える