1 [[!meta date="2016-10-05 21:48:11 +0800"]]
4 Getting used to the grammar of ggplot2 takes some time, but so far it's not been disappointing. Wanting to split a scatterplot by segment, I used `facet_grid`. That by default shows a label on each subplot, using the values in the variable by which the plot is faceted.
6 As that often isn't very descriptive in itself, there needs to be a way to re-label these subplots. That way is `as_labeller`, as shown in the example code below.
10 ggplot(outputs, aes(x=date_var,y=value_var),alpha=0.8) +
11 geom_point(aes(y=value_var, colour=colour_var)) +
13 theme(legend.position = "none",axis.text.y = element_blank(),axis.text.x = element_blank()) +
14 scale_x_date(date_breaks = '1 week') +
15 labs(y = "Value",x = "Date", title = "Example") +
16 scale_colour_manual("Legend",values=named_coloring_vector)) +
17 scale_fill_manual("",values=c("grey12")) +
18 facet_grid(. ~ Segment, labeller = as_labeller(c("yes" = "Segment A",
23 [[!img pics/2016-10-05_R-facet.png size="200x200" alt="Example plot with 2 facets labelled Segment B and Segment A"]]