ggplot scale_x_date date_breaks参数无法识别

时间:2016-01-08 18:56:13

标签: r ggplot2

它似乎没有记录的工作......任何想法?

x <- data.frame(date=as.Date(c("2015-12-01", "2015-12-03", "2015-12-15", "2015-12-28")), N=c(1,3,2,4))
ggplot(x, aes(date, N)) + geom_bar(stat="identity") + scale_x_date(date_breaks="1 day")
Error in continuous_scale(aesthetics, "date", identity, breaks = breaks,  : 
  unused argument (date_breaks = "1 day")

1 个答案:

答案 0 :(得分:3)

正如我评论的那样:

library(ggplot2)
last_month <- Sys.Date() - 0:29
df <- data.frame(
    date = last_month,
    price = runif(30)
)
base <- ggplot(df, aes(date, price)) +
    geom_line()

base + scale_x_date(breaks = "1 day")

使用您的数据:

ggplot(x, aes(date, N)) + geom_bar(stat="identity") + scale_x_date(breaks="1 day")

enter image description here