我有一个名为“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的值,但我仍然得到错误。 你知道这段代码有什么问题吗?错误来自何处,以及如何使其发挥作用?
谢谢
答案 0 :(得分:0)
喜欢这个? (以下代码)
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)