-5

I am working on a project trying to figure out if there is any correlation between the baseball WAR statistic and a player's salary. I've got a data frame that has both the WAR and the salary. I then go to plot them and I have no idea what is happening, so I think I might have done something wrong on a fundamental level.

this.is.war.2015 <- this.is.war %>%
  filter(year_ID == 2015)
this.sal.2015 <- this.is.war.2015 %>%
  select(salary)
this.war.2015 <- this.is.war.2015 %>%
  select(WAR)
this.sal.2015.2 <- this.sal.2015[2:3,]
this.war.2015.2 <- this.war.2015[2:3,]
plot(this.war.2015.2, this.sal.2015.2)
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 1
    Your question is quite vague. What exactly is the problem? Do you not like the plot? If so -- why not? We can neither read your mind nor produce your plot since we lack the requisite data. Please give a [mcve]. See this for tips on how to do so in R: https://stackoverflow.com/q/5963269/4996248 – John Coleman May 29 '17 at 18:31

2 Answers2

1

I tried running your code with some dummy data, and it worked. Notice that you plot only two points.

    library(dplyr)
    this.is.war <- data.frame(year_ID = c(2013,2014,2015,2015,2015),
                              salary = rnorm(n = 5,mean = 1000,sd = 200),
                              WAR = rnorm(n=5,mean = 6, sd = 2))


    this.is.war.2015 <- this.is.war %>% filter(year_ID == 2015)
    this.sal.2015 <- this.is.war.2015 %>% select(salary)
    this.war.2015 <- this.is.war.2015 %>% select(WAR)
    this.sal.2015.2 <- this.sal.2015[2:3,]
    this.war.2015.2 <- this.war.2015[2:3,]
    plot(this.war.2015.2, this.sal.2015.2)

Not sure why it didn't work for you, probably because your data frame is not set up correctly.

Anyhow, a much cleaner code would be:

    data2015 <- this.is.war %>% filter(year_ID == 2015)
    plot(data2015[2:3,'WAR'],data2015[2:3,'salary'])

Or if you didn't plan to use only two samples, it would be:

    data2015 <- this.is.war %>% filter(year_ID == 2015)
    plot(data2015$WAR,data2015$salary)
Omri374
  • 2,555
  • 3
  • 26
  • 40
0

I'm not entirely sure what your question is, but if you type ?plot in your console you can see a help page for the plot function. The plot function is really awesome, as it does a lot of things automatically for you (like axis labels and such). I can't see your plot output, but it looks like this.war.2015.2 is your x axis value, and this.sal.2015.2 is your y axis value.

Hope this helps.

kpr62
  • 522
  • 1
  • 4
  • 11