1

So, I've got a large dataset (around 400 000 observations) of data from auctions. I'm trying to use ggplot to plot auction prices by day, while denoting year by color and month using vertical lines.

I have a POSIXlt vector that holds my dates, here is what I'm working with:

firstmonth<- c(1,32,60,91,121,152,182,213,244,274,305,335)

require(ggplot2)
p <- ggplot(bb, aes(saledate$yday, SalePrice))
p <- p + geom_point(aes(color = factor(saledate$year)), alpha = I(1/30)) #This plot works
p + geom_vline(aes(xintercept = firstmonth))
Error in data.frame(xintercept = c(1, 32, 60, 91, 121, 152, 182, 213,  : 
  arguments imply differing number of rows: 12, 401125

What's with this error? Why can't I get the vertical lines?

4

1 に答える 1

6

新しいdata.frameをgeom_vline:に渡す必要があります。

library(ggplot2)

bb <- data.frame(SalePrice=rnorm(1000))
saledate <- data.frame(yday=1:1000,year=rep(1:10,each=100))

firstmonth<- c(1,32,60,91,121,152,182,213,244,274,305,335)

p <- ggplot(bb, aes(saledate$yday, SalePrice))
p <- p + geom_point(aes(color = factor(saledate$year))) #This plot works
p + geom_vline(aes(xintercept = firstmonth))
#error
df2 <- data.frame(firstmonth)
p + geom_vline(data=df2,aes(xintercept = firstmonth))
#works
于 2013-03-01T19:58:23.127 に答える