0

I have a data frame that is comprised of the stats of nba players. The id of each element is the player's name, and the other columns in the data frame contain stats (numeric class) and factor variables like the player's team. I am trying to plot the relationship between two statistics for each player, and then facet the plots by the player's position (factor variable). When I make the plot (code below) the player's team data is jumbled, and misapplied to the players.

The below code shows what position players should be assigned to

example <- arrange(combined, desc(cap.adjusted.worp))
head(example[, 1:3])

> head(example[, 1:3])
Tm            Player Pos
1 GSW     Stephen Curry  PG
2 OKC Russell Westbrook  PG
3 CLE      LeBron James  SF
4 HOU      James Harden  SG
5 TOR        Kyle Lowry  PG
6 OKC      Kevin Durant  SF

Code to make plot

gg <- ggplot(combined, aes(combined$Salary / 1000000, combined$cap.adjusted.worp))
gg <- gg + geom_point() + facet_wrap(~Pos, nrow = 1)
gg <- gg + geom_text(label = combined$Player, size = 2.5)
gg <- gg + xlab("Salary in Millions") + ylab("Cap Adjusted WORP")
gg <- gg + geom_vline(xintercept = combined$avg.salary / 1000000, combined)
gg <- gg + geom_hline(yintercept = combined$avg.worp, combined)
gg <- gg + geom_smooth(method = "lm", se = FALSE, size = 1)
gg <- gg + ggtitle("Relationship between Cap Adjusted Wins Over Replacement Player and Salary by Player")
gg

My plot with the misapplied or labeled position variables

steph curry is a PG in dataframe and a PF in plot, many other examples of jumbled positions for players

*I don't have enough reputation points to post images so here is an imgur link to the plot made from the above code https://i.stack.imgur.com/BnumJ.jpg

buchmayne
  • 144
  • 1
  • 15
  • Or in many cases, `aes()` not being used at all! – Gregor Thomas Aug 08 '16 at 17:52
  • In case it's not clear from the dupe, you shouldn't have a single `$` in your code for this plot. `ggplot(combined, aes(x = Salary / 1e6, y = cap.adjusted.worp)) + ... + geom_vline(aes(xintercept = avg.salary / 1e6)) + geom_hline(aes(yintercept = avg.worp)) + ...` – Gregor Thomas Aug 08 '16 at 17:55

0 Answers0