或基R和GGPLOT2解決方案:
# date object
d$month2 <- as.Date(as.character(d$month), "%Y-%d-%m")
> str(d)
'data.frame': 5 obs. of 3 variables:
$ count : int 3 4 3 12 12
$ month : Factor w/ 5 levels "2014-10-01","2014-13-02",..: 1 4 2 3 5
$ month2: Date, format: "2014-01-10" "2014-01-15" "2014-02-13" "2014-02-14" ...
# per month
res <- aggregate(d$count, list(months(d$month2)), sum)
# again a date object
res$month <- as.Date(paste0("01-", res$Group.1, "-2014"), "%d-%B-%Y")
# plot
ggplot(res, aes(x= month, y=x)) +
geom_point() + geom_line() +
scale_x_date(date_minor_breaks = "1 month",date_labels = "%B")
您也可以嘗試包括,原始數據爲每塊地塊點和計數:
ggplot(d, aes(x= month2, y=count)) +
geom_point(col="red") +
scale_x_date(date_minor_breaks = "1 month",date_labels = "%B") +
geom_bar(data = res, aes(x= month, y=x),stat = "identity", position = 'identity',width=0.5)
可以嘗試變換的日期爲[yearmon對象(https://開頭www.rdocumentation.org/packages/zoo/versions/1.7-14/topics/yearmon),然後您可以輕鬆進行分組,因爲它的行爲與一個因素類似。 – cylim