0

I want to do something that I thought would be simple but I can't find the answer anywhere. I have the following graph, which maps the goal differential of various hockey teams over time. I would like to make it so that one specific team stands out, preferably by making its line size bigger. Here's the graph:

The graph

And here's the code that generated it:

p <- ggplot(data = NHLRegularSeason.2014.2015, aes(x = Date, y = GPlusMinus, group = Team, color = Team))
p + geom_smooth(fill = NA)

Is there a way to add another style to just one specific team?

If it helps, here's how I created a subset of a specific team:

RangersRegularSeason <- subset(NHLRegularSeason.2014.2015, Team == "NYR")
Jake
  • 733
  • 2
  • 7
  • 18

2 Answers2

3

Since you have already defined a subset, the following should work:

ggplot(data = NHLRegularSeason.2014.2015, aes(x = Date, y = GPlusMinus, group = Team)) +
  geom_smooth(fill = NA) +
  geom_smooth(data = RangersRegularSeason, aes(color = Team, fill = NA))

NOTE: It is easier for others to help you if you provide a reproducible example.

Community
  • 1
  • 1
JasonAizkalns
  • 20,243
  • 8
  • 57
  • 116
  • Thanks so much, that worked! One more question if you have a sec: I liked the idea of adding a subset on the fly as Monhawk alluded to by doing: p + geom_smooth(fill = NA) + geom_smooth(aes(x = Date[Team == 'NYR'], y = GPlusMinus[Team == 'NYR'], size = 2)) but that gave me this error: Error: Aesthetics must either be length one, or the same length as the dataProblems:Date[Team == "NYR"], GPlusMinus[Team == "NYR"] is there a reason that didn't work? – Jake Nov 02 '15 at 18:17
  • 1
    @Jake just pass the entire subset statement into data. So in this case, the last call to `geom_smooth` would become: `geom_smooth(data = subset(NHLRegularSeason.2014.2015, Team == "NYR"), aes(color = Team, fill = NA))`. Then, if you wanted to subset a different team, simply change the `Team == "NYR"` to something else and add additional criteria to the `subset` call. Anything more complicated than that and you'll probably want to post a new question -- but please try and make the question reproducible. – JasonAizkalns Nov 02 '15 at 18:22
  • Thanks again! Really appreciate it – Jake Nov 02 '15 at 18:23
2

You can just specify additional layers:

library(ggplot2)

data(iris)

ggplot(iris) +
  geom_point(aes(Sepal.Width, Sepal.Length, colour = Species)) +
  geom_point(aes(Sepal.Width[Species == "setosa"], Sepal.Length[Species == "setosa"], colour = "setosa", size = 2))
m0nhawk
  • 22,980
  • 9
  • 45
  • 73
  • Thanks a lot, only problem I'm having now is that I'm getting this error: Error: Aesthetics must either be length one, or the same length as the dataProblems:Date[Team == "NYR"], GPlusMinus[Team == "NYR"] – Jake Nov 02 '15 at 18:06
  • @Jake looks very strange, you may have some `Date` or `GPlusMinus` variables or something like that. – m0nhawk Nov 02 '15 at 18:15