r - Split dataset by grouping variable to create multiple bar plots at once -
i have large dataset looks this:
time, precip, grp
2005-09-30 11:45:00,1.1,1
2005-09-30 23:45:00,1.5,1
2005-10-01 23:45:00,0.2,2
2005-10-02 11:45:00,0.3,2
2005-10-02 23:45:00,1.7,2
2005-10-03 11:45:00,0.8,2
2005-10-04 23:45:00,1.4,4
i want make separate data frames each group (grp, there total of 65 groups in full dataset) , produce bar graph each group.
so far, i've made list:
x <- split(df, df$grp) str(x) y <- lapply(seq_along(x), function(x) as.data.frame(x[[x]])[, 1:2]) lapply(seq_along(y), function(x) {assign(grp[x], y[[x]], envir=.globalenv)})
which produces this:
>y >[[1]] time precip 3 2005-10-01 11:45:00 0 8 2005-10-03 23:45:00 0 9 2005-10-04 11:45:00 0 [[2]] time precip 1 2005-09-30 11:45:00 1.1 2 2005-09-30 23:45:00 1.5 ...
is there way plot each of these have different bar graph each group, time on x-axis , precip on y-axis? ideally, bar graphs on same page or part of same output.
also, there way export each of these separate data frames?
thank in advance!
lattice
made sort of thing.
using royalts's data df
:
library(lattice) barchart(time~precip|grp, data=df)
Comments
Post a Comment