0

I have a dataset called "alldata", which contains 1000 rows and 2 columns named "day_of_Week" and "label". The dataset look like this :

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

I'm using ggplot2 to plot the data,

ggplot(alldata, aes(day_of_Week, fill = label)) + geom_density(alpha = 0.2) + xlim(55, 70)

But, I get this error

Error: Discrete value supplied to continuous scale

I have changed the value about xlim or alpha, but I still get the error. Do you have any idea what's wrong with this code? where is the error from, and how can I make it work?

Thank you

UseR10085
  • 7,120
  • 3
  • 24
  • 54
estu
  • 117
  • 1
  • 3
  • 9
  • 1
    I think you are supplying factor or character for something ggplot expects numeric. You may want to check classes with `str(alldata)` – jazzurro Nov 28 '15 at 01:50

1 Answers1

0

Like this? (code below)

geom_density

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

Possible more illustrative

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)

enter image description here

Eric Fail
  • 8,191
  • 8
  • 72
  • 128
  • Thank you for the explanation before. But the same error still there when I add the code with xlim(55,70). Do you know why xlim cant work with the data? – estu Nov 28 '15 at 05:15
  • I'm not sure what you want, but the range `range(alldata$day_of_Week)` of your x variable is 2:6, obviously `xlim(55,70)` don't make much sense. I ran `+ xlim(3, 5)` and it worked fine fro me. Does that answer your issue? – Eric Fail Nov 28 '15 at 15:41