I have a time series (albeit small scale i.e., 4 days) dataset that consists of four groups, say, types of granola. Some of the ingredients are shared among the types of granola, so that granola "A" consists of ingredient "x", "y", "c", "f" and granola "B" consists of "g", "t", "f", "e". Granola "A" and Granola "B" both contain ingredient "f"
I am trying to plot how much of each ingredient an animal eats from the offered granola sample on each of the days.
I've tried using the 'group' call in 'geom_raster()' but that has no effect.
Here is some sample data:
'test.df <- data.frame(day = c(rep(1, 4), rep(2, 4), rep(3,4), rep(4,4), rep(1,5), rep(2,5), rep(3,5), rep(4,5),
rep(1, 3), rep(2, 3), rep(3,3), rep(4,3), rep(1, 4), rep(2, 4), rep(3,4), rep(4,4)),
spp = rep("species A"),
type = c(rep("A", 16), rep("B", 20), rep("C", 12), rep("D", 16)),
comp = c(rep(c("ss", "pe", "mi", "li"),4), rep(c("co", "csf", "cd", "ah", "mi"),4),
rep(c("cd", "cgf", "ah"),4),
rep(c("di", "csf", "xi", "ef"),4)),
value = sample(0.0:60.0, 64, replace = T))
ggplot(test.df) +
geom_raster(aes(x = day, y = comp, group= type, fill = value)) +
scale_fill_gradientn(colours = rainbow(10)) +
coord_equal()
I'm hoping to get the y-axis to display each component by group such that like components are not combined.
UPDATE: I made an object for each group, then plotted each out. The end result I am looking for would have the four plots stacked to make one plot.
A <- test.df %>%
filter(type == "A")
B <- test.df %>%
filter(type == "B")
C <- test.df %>%
filter(type == "C")
D <- test.df %>%
filter(type == "D")
ggplot(A) +
geom_raster(aes(x =day, y = comp, fill = value)) +
scale_fill_gradientn(colours = rainbow(10)) + coord_equal() +
ylab("A")
ggplot(B) +
geom_raster(aes(x =day, y = comp, fill = value)) +
scale_fill_gradientn(colours = rainbow(10)) + coord_equal() +
ylab("B")
ggplot(C) +
geom_raster(aes(x =day, y = comp, fill = value)) +
scale_fill_gradientn(colours = rainbow(10)) + coord_equal() +
ylab("C")
ggplot(D) +
geom_raster(aes(x =day, y = comp, fill = value)) +
scale_fill_gradientn(colours = rainbow(10)) + coord_equal() +
ylab("D")