I have data In three flavours and want to show it as three different plots in a chart. I also want to use geom_smooth on the plots. When one of the flavours of data has less than seven values, geom_smooth can not be rendered for that plot. This is fine, since it is rendered for the other plots. (second example) However, I noticed that when one of the flavours has two or less values, geom_smooth is not rendered for any of the plots in the chart. I would like to use geom_smooth on the other two flavours even though one flavour has below two data points.
I find the warnings/errors hard to interpret since they change depending on how many data points the last flavour has.
Example with two data points
library(ggplot2)
dat <- data.frame("Year" = c(1:10, 1:10, 4,5),
"Val" = c(46,57,36,58,36,57,36,56,46,58,
23,28,26,38,26,37,26,26,36,38,
3,5),
"Flavour" = c(rep("type A",10), rep("type B", 10), rep("type C",2)))
ggplot(dat, aes(x = Year,
y = Val,
color = Flavour,
group = Flavour)) +
geom_smooth(alpha = 0.5) +
geom_line() +
geom_point()
Example with more than two data points
library(ggplot2)
dat <- data.frame("Year" = c(1:10, 1:10, 1:3),
"Val" = c(46,57,36,58,36,57,36,56,46,58,
23,28,26,38,26,37,26,26,36,38,
3,5,5),
"Flavour" = c(rep("type A",10), rep("type B", 10), rep("type C",3)))
ggplot(dat, aes(x = Year,
y = Val,
color = Flavour,
group = Flavour)) +
geom_smooth(alpha = 0.5) +
geom_line() +
geom_point()