使用 Geom_Point(color) 时从 ggplot(scatterplot) 中删除结果

Removing Results from ggplot(scatterplot) when using Geom_Point(color)

我正在尝试删除散点图上的灰点,但无法成功。我在下面附上了我正在使用的代码行。我相信使用子集会有所帮助,但认为 geom_point 中的 "color" 只会应用 "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"))

灰点是数据集中所有没有由您在函数中传递的元素定义颜色的俱乐部 lims。因此,要删除灰点,您可以对数据框进行子集化以仅保留感兴趣的俱乐部:

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)

如果这不起作用,请考虑提供一个可重现的数据集示例,请参阅此 link 了解如何操作:How to make a great R reproducible example