-1

MLS Draft Scatterplot

I am trying to remove the grey points on my scatterplot and can't manage to do so. I have attached the lines of code that I am using below. I believe that using a subset would help but thought that the "color" in geom_point would only apply the points from the selected variables in "color"

ggplot(MLS_Draft_File, aes(x = MLS_Draft_File$`Overall Pick Number`, 
                           y = MLS_Draft_File$`Percentage of Minutes Played`)) +
geom_point(aes(color = MLS_Draft_File$`Drafting Club`)) + 
lims(color = c("New York City FC", "Orlando City SC", "Atlanta United FC", "Minnesota United FC", "Los Angeles FC", "FC Cincinnati"))
SKnuth
  • 3
  • 4
  • You could use a different theme, e.g. `theme_minimal()`; for more fine-tuning, you can delete/modify individual canvas/plot elements within `theme`. See e.g. [Remove grid and background from plot](https://felixfan.github.io/ggplot2-remove-grid-background-margin/) – Maurits Evers Feb 12 '20 at 22:06
  • Are you talking about grey points ? or grey background ? – dc37 Feb 12 '20 at 22:08
  • Possible duplicate of [Remove grid, background color, and top and right borders from ggplot2](https://stackoverflow.com/questions/10861773/remove-grid-background-color-and-top-and-right-borders-from-ggplot2) – Maurits Evers Feb 12 '20 at 22:09
  • 1
    Unrelated to issue: don't use `$` inside `aes()`. Just use the unquoted column name. – neilfws Feb 12 '20 at 22:09
  • @dc37 the grey points. – SKnuth Feb 12 '20 at 22:11

1 Answers1

0

Grey points are all clubs in your dataset that don't have a color defined by elements you passed in your function lims. So, to remove grey points, you can subset your dataframe to keep only clubs of interest:

library(ggplot2)
club <- c("New York City FC", "Orlando City SC", "Atlanta United FC", "Minnesota United FC", "Los Angeles FC", "FC Cincinnati")
ggplot(subset(MLS_Draft_File, `Drafting Club` %in% club), aes(x = `Overall Pick Number`, 
                           y = `Percentage of Minutes Played`)) +
  geom_point(aes(color =`Drafting Club`)) + 
  lims(color = club)

If this is not working, please consider providing a reproducible example of your dataset, see this link to know how to do it: How to make a great R reproducible example

dc37
  • 15,840
  • 4
  • 15
  • 32