ggplot2 error:Discrete value supplied to continuous scale R
ggplot2 error:Discrete value supplied to continuous scale R
我有一个名为“alldata”的数据集,其中包含 1000 行和 2 列,分别名为“day_of_Week”和“label”。数据集如下所示:
day_of_Week label
5 Wday, Clicked
2 Wday, Clicked
4 Wday, Clicked
4 Wday, Clicked
2 Wday, Clicked
6 Wday, Clicked
2 Wday, Clicked
2 Wday, Clicked
3 Wday, Clicked
2 Wday, Clicked
我正在使用 ggplot2 绘制数据,
ggplot(alldata, aes(day_of_Week, fill = label)) + geom_density(alpha = 0.2) + xlim(55, 70)
但是,我得到了这个错误
Error: Discrete value supplied to continuous scale
我已经更改了有关 xlim 或 alpha 的值,但仍然出现错误。
你知道这段代码有什么问题吗?错误来自哪里,我该如何解决?
谢谢
像这样? (下面的代码)
alldata <- structure(list(day_of_Week = c(5L, 2L, 4L, 4L, 2L, 6L, 2L, 2L,
3L, 2L), label = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = "Wday, Clicked", class = "factor")), .Names = c("day_of_Week",
"label"), class = "data.frame", row.names = c(NA, -10L))
# install.packages("ggplot2", dependencies = TRUE)
require(ggplot2)
m <- ggplot(alldata, aes(x = day_of_Week))
m + geom_density(aes(fill=label))
可能更具说明性
alldata$label2 <- rep(c("Wday, Clicked", "Wday, Not clicked"), 5)
m <- ggplot(alldata, aes(x = day_of_Week))
m + geom_density(aes(fill=label2), alpha=0.3)
我有一个名为“alldata”的数据集,其中包含 1000 行和 2 列,分别名为“day_of_Week”和“label”。数据集如下所示:
day_of_Week label
5 Wday, Clicked
2 Wday, Clicked
4 Wday, Clicked
4 Wday, Clicked
2 Wday, Clicked
6 Wday, Clicked
2 Wday, Clicked
2 Wday, Clicked
3 Wday, Clicked
2 Wday, Clicked
我正在使用 ggplot2 绘制数据,
ggplot(alldata, aes(day_of_Week, fill = label)) + geom_density(alpha = 0.2) + xlim(55, 70)
但是,我得到了这个错误
Error: Discrete value supplied to continuous scale
我已经更改了有关 xlim 或 alpha 的值,但仍然出现错误。 你知道这段代码有什么问题吗?错误来自哪里,我该如何解决?
谢谢
像这样? (下面的代码)
alldata <- structure(list(day_of_Week = c(5L, 2L, 4L, 4L, 2L, 6L, 2L, 2L,
3L, 2L), label = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = "Wday, Clicked", class = "factor")), .Names = c("day_of_Week",
"label"), class = "data.frame", row.names = c(NA, -10L))
# install.packages("ggplot2", dependencies = TRUE)
require(ggplot2)
m <- ggplot(alldata, aes(x = day_of_Week))
m + geom_density(aes(fill=label))
可能更具说明性
alldata$label2 <- rep(c("Wday, Clicked", "Wday, Not clicked"), 5)
m <- ggplot(alldata, aes(x = day_of_Week))
m + geom_density(aes(fill=label2), alpha=0.3)