Question: I'm working on a project where I'm getting a large (70k) array of bytes. 

I have to decode it and parse the result properly, based on the data.

Array is built like this:

```
{ header_cells, dataType1, dataType1..., dataType2, dataType2...}

```

Is it the best solution to use here the ByteBuffer?I know all lengths, basically I wanted to split it using:

```
byte[] arr = new byte[SIZE];
byte[] output = buffer.get(arr, offset, length);

```

And the wrap it into my objects.

Is it a good solutioon, or is there something better?

Answer: 
I'm not an expert on `ggplot2`, but I think you lose the legend because you remove your aesthetic mapping in `geom_bar` with the argument assignment `fill=Palette`. Essentially, your `fill` aesthetic is not just by `Response`, but by a combination of `Response` and `Group`, because each group has a different color for the same response (which may be a questionable practice, but that's not for me to decide).

I think this code gives you what you want. I added a `helper` field to `data1` in order to have the proper `fill` aesthetic. Note I needed to manually override the legend labels in `scale_fill_manual`

```
library(dplyr)
data1<- as.data.frame(data %>% 
    group_by(Group, Time, Response) %>%                     
    summarise(N= n())) %>%
  mutate(helper = as.character(group_indices(., Group, Response)))

# Define the color for control and treatment groups
trtCol <- c("#deebf7", "#9ecae1","#3182bd")
conCol <- c("#e5f5e0", "#a1d99b", "#31a354")
Palette<-c(conCol, trtCol, conCol, trtCol, conCol, trtCol)

library(ggplot2)
library(scales)

# Specify color in ggplot using "geom_bar (fill=Palette)"
ggplot(data1, aes(Group, N, fill = helper)) + 
  facet_wrap(~Time, strip.position = "bottom") +
  labs(title="Distribution of Responses by Groups over Time", x="Time Points", y="Percentage") +
  scale_fill_manual(name = "Response", values = Palette, labels = c(1, 2, 3, 1, 2, 3)) +
  geom_bar(position = "fill",stat = "identity") + 
  scale_y_continuous(labels = percent_format()) + 
  theme_classic() +
  theme(plot.title = element_text(hjust = 0.5), axis.text.x=element_blank(), axis.ticks.x=element_blank(), 
        panel.spacing = unit(0.1, "lines"))+
  geom_text(aes(x=0,y=-0.05,label="Control\nGroup"), size=3.5)+
  geom_text(aes(x=1,y=-0.05,label="Treatment\nGroup"), size=3.5)

```
I used the code Zack suggested, and added "guides(fill=guide\_legend(ncol=2))" to it. This is the graph I got

[Revised graph](https://i.stack.imgur.com/5LrOm.png)