0

我有一个名为“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)

但是,我得到这个错误

错误:提供给连续刻度的离散值

我已经更改了有关 xlim 或 alpha 的值,但我仍然收到错误消息。你知道这段代码有什么问题吗?错误来自哪里,我怎样才能让它工作?

谢谢

4

1 回答 1

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)

在此处输入图像描述

于 2015-11-28T02:29:52.590 回答