0
votes

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

1
I think you are supplying factor or character for something ggplot expects numeric. You may want to check classes with str(alldata)jazzurro

1 Answers

0
votes

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