Reputation: 1480
I have a data set that I have built the following plot around:
The plot is fed from a data set included at the bottom of this post, and is made from the following ggplot2 code:
ggFacetProfile <- ggplot(sub, aes(group = iMoYr)) +
geom_line(aes(x= iHrMi, y = trimAv)) +
facet_grid(off ~ iMoYr, scales = "free") +
ggtitle("Typical Half Hourly Profiles") +
xlab("Time") + ylab("Energy (kWh)")
Here I am plotting the values trimAv
(effectively average values) over iHrMi
(effectively hour and minute). This is on a facet of off
by iMoYr
(effectively is the process on of off, and different months over the year).
The data table already has the effective smoothed value ranges calculated in it, under the heading minEcl
and maxEcl
. I would like to be able to use geom_smooth to represent this data on the graph as boundaries of the shape made by the function geom_smooth, however I haven't been able to locate a way to bypass calling stat_smooth.
My closest attempt so far is to include:
+ geom_smooth(aes(x= iHrMi, y = trimAv, ymin = minEcl, ymax = maxEcl))
However, this is coerced into a loess smoothing, apparently due to the size of the data, which looks like this:
Is it possible to feed geom_smooth specific pre-calculated values, or am I trying to use geom_smooth in very much the wrong way? It seems incongruous that the other geom_ arguments in ggplot2 are so adaptable and this seems so rigid.
The head and tail of the data source (a data table) is included below for structure purposes:
iDate off trimAv trimStD minEcl maxEcl iMoYr iHrMi
1: 2013-08 00:00 Production 136.52273 37.300389 76.4 218.4 2013-08 00:00
2: 2013-08 00:30 Production 136.14091 36.117819 80.3 217.7 2013-08 00:30
3: 2013-08 01:00 Production 133.92500 32.808662 76.9 213.3 2013-08 01:00
4: 2013-08 01:30 Production 139.20476 37.929480 77.1 221.5 2013-08 01:30
5: 2013-08 02:00 Production 137.82857 36.422042 74.9 221.0 2013-08 02:00
---
1148: 2014-07 22:30 Non-Production 50.51250 3.025812 47.1 56.3 2014-07 22:30
1149: 2014-07 23:00 Non-Production 49.88571 2.066743 47.0 52.6 2014-07 23:00
1150: 2014-07 23:30 Non-Production 49.94286 2.318661 46.5 52.5 2014-07 23:30
1151: 2014-07 00:00 Non-Production 50.85714 2.860569 47.9 54.9 2014-07 00:00
1152: 2014-07 00:30 Non-Production 50.72857 4.181194 47.6 59.1 2014-07 00:30
If I can include the source data in a better/ more suitable form please let me know in the comments.
Upvotes: 2
Views: 269
Reputation: 791
Maybe you are looking for geom_ribbon
.
ggFacetProfile <- ggplot(sub, aes(group = iMoYr)) +
geom_line(aes(x= iHrMi, y = trimAv)) +
facet_grid(off ~ iMoYr, scales = "free") +
ggtitle("Typical Half Hourly Profiles") +
xlab("Time") + ylab("Energy (kWh)") +
geom_ribbon(aes( ymin = minEcl, ymax = maxEcl))
Upvotes: 1