我想绘制一个数据框中的两列。一个是b获胜和亏损,已转换为二进制1和0。另一个是距体育场的距离。但是,我将距离转换为“> 600km及以下”,“ 601km至1200km”,“ 1201km至1800km”等类别,直至> 4500km。我这样做是因为有很多游戏,我想看看离家不远和离家不远之间是否存在联系。
但是,我现在停留在如何绘制图形上,因为它的非数字参数会导致二进制运算符错误。
我在Rstudio中。
lat1 <- 37.75028
long1 <- -122.2029
lat2 <- OaklandAwayGamesM$latitude
long2 <- OaklandAwayGamesM$longitude
earth.dist <- function (long1, lat1, long2 , lat2)
{
rad <- pi/180
a1 <- lat1 * rad
a2 <- long1 * rad
b1 <- lat2 * rad
b2 <- long2 * rad
dlon <- b2 - a2
dlat <- b1 - a1
a <- (sin(dlat/2))^2 + cos(a1) * cos(b1) * (sin(dlon/2))^2
OaklandAwayGamesM$Distance_From_Oakland1[OaklandAwayGamesM$Distance_From_Oakland>0 & OaklandAwayGamesM$Distance_From_Oakland<= 600 ] =
"600km and under"
OaklandAwayGamesM$Distance_From_Oakland1[OaklandAwayGamesM$Distance_From_Oakland>601
& OaklandAwayGamesM$Distance_From_Oakland<= 1200 ] = "601km to 1200km"
OaklandAwayGamesM$Distance_From_Oakland1[OaklandAwayGamesM$Distance_From_Oakland>1201
& OaklandAwayGamesM$Distance_From_Oakland<= 1800 ] = "1201km to 1800km"
OaklandAwayGamesM$Distance_From_Oakland1[OaklandAwayGamesM$Distance_From_Oakland>1801
& OaklandAwayGamesM$Distance_From_Oakland<= 2400 ] = "1801km to 2400km"
OaklandAwayGamesM$Distance_From_Oakland1[OaklandAwayGamesM$Distance_From_Oakland>2401
& OaklandAwayGamesM$Distance_From_Oakland<= 3000 ] = "2401km to 3000km"
OaklandAwayGamesM$Distance_From_Oakland1[OaklandAwayGamesM$Distance_From_Oakland>3001
&
OaklandAwayGamesM$Distance_From_Oakland<= 3600 ] = "3001km to 3600km"
OaklandAwayGamesM$Distance_From_Oakland1[OaklandAwayGamesM$Distance_From . _Oakland>3601
&
OaklandAwayGamesM$Distance_From_Oakland<= 4200 ] = "3601km to 4200km"
OaklandAwayGamesM$Distance_From_Oakland1[OaklandAwayGamesM$Distance_From_Oakland>4201
&
OaklandAwayGamesM$Distance_From_Oakland<= 4500 ] = "4201km and above"
boxplot(OaklandAwayGamesM$Distance_From_Oakland1,
OaklandAwayGamesM$Win1_loss0,
ylab = "Wins Away from Home", xlab = "Distance from Home Stadium",
main = "Wins Away Vs Distance", col ="blue", pch=16)
Error in x[floor(d)] + x[ceiling(d)] :
non-numeric argument to binary operator
我只是希望能够绘制一些图表来查看胜利和离主场的距离。