Question: I want to use ggplot to show points and lines, but I want there to be two legends - one for the points and one for the lines.

I managed to do this using the below code, but for some reason the 'size' option no longer responds in geom\_point and they are stuck at the fairly ugly size you can see in the image
![](https://i.stack.imgur.com/cfQBR.png).

Note that I chose stroke = NA because I do not want the points to have a border. The code is below.

Any ideas?

```
ggplot(data = plot_data) +
    geom_point(aes(x = z.1, y = obs, fill = treatcat), alpha = 0.4, shape = 21, stroke = NA, size = 1) +
    geom_line(aes(x = z.1, y = under, colour = "True"), linetype = "dashed") +
    geom_line(aes(x = z.1, y = crude, colour = "Crude"), size = 1.5) +
    scale_fill_manual(name = "Treatment",
                        values = c("0" = "#F8766D", "1" = "#C77CFF"),
                        breaks = c("0", "1"),
                        labels = c("Untreated", "Treated")) + 
    scale_colour_manual(name = "Model",
                        values = c("Crude" = "orange", "True" = "black"),
                        breaks = c("Crude", "True"),
                        labels = c("Crude", "True")) + 
    ylim(-30,27.5) +
    theme(plot.title = element_text(size = "12")) +
    labs(title = "Fitted Values for Crude Model", x = "Z", y = "Y(1)")

```

Answer: 
You are wrongly using the salaries `highest` and `otherHighest` as indexes into the arrays `baseballArray` and `basketballArray`!
There are 3 main bugs in your code, in order of appearance:

* `highest` and `otherHighest` are not initialized
* As pointed out by Kim Nyholm the salaries are used as indexes
* Then `highest` and `otherHighest` are used as salaries instead of indexes

```
// Initialized as index of the first element
int highest = 0;
int otherHighest = 0;

for (int i = 0; i < SIZE; i++) {
    if (baseballArray[highest].getSalary() < baseballArray[i].getSalary())
        highest = i; // Stores the index

    if (basketballArray[otherHighest].getSalary() < basketballArray[i].getSalary())
         otherHighest = i; // Stores the index
}

// Compares the salaries
if (baseballArray[highest].getSalary() > basketballArray[otherHighest].getSalary())
    baseballArray[highest].printStats();
else if (basketballArray[otherHighest].getSalary() > baseballArray[highest].getSalary())
    basketballArray[otherHighest].printStats();
else // if (baseballArray[highest].getSalary() == basketballArray[otherHighest].getSalary())
    cout << "error";

```