我想使用ggplot2绘制数据。我的数据结构如下所示:
str(res)
'data.frame': 1161 obs. of 4 variables:
$ gesamt : num 66.6 32.9 52.5 23.9 17.7 ...
$ ITEMGROUPID : chr "1011113" "1011113" "1011113" "1011113" ...
$ Salesname : Factor w/ 2 levels "Hornbach Baumarkt CZ spol. s r.o.",..: 2 2 2 2 2 2 2 2 2 2 ...
$ deliverydate: POSIXct, format: "2014-01-07" "2014-01-31" "2014-02-10" "2014-03-06" ...
我想用这个代码facett我的数据:
ggplot(data = res, aes(x = res$deliverydate, y = res$gesamt, colour = res$Salesname)) +
geom_point() +
facet_wrap(~res$ITEMGROUPID)
但我得到了这个错误:
Error in layout_base(data, vars, drop = drop) :
At least one layer must contain all variables used for facetting
我应该怎么做来解决这个问题?
一个可重复的例子:
> dput(head(res))
structure(list(gesamt = c(66.6, 32.86, 52.54, 23.89, 17.74, 45.05
), ITEMGROUPID = c("1011113", "1011113", "1011113", "1011113",
"1011113", "1011113"), Salesname = structure(c(2L, 2L, 2L, 2L,
2L, 2L), .Label = c("Hornbach Baumarkt CZ spol. s r.o.", "Possling GmbH & Co. KG"
), class = "factor"), deliverydate = structure(c(1389049200,
1391122800, 1391986800, 1394060400, 1394751600, 1395874800), class = c("POSIXct",
"POSIXt"), tzone = "")), .Names = c("gesamt", "ITEMGROUPID",
"Salesname", "deliverydate"), row.names = c(NA, 6L), class = "data.frame")
1条答案
按热度按时间s4n0splo1#
这个应该能帮你。