Re: [R] Plotting lines to sets of points

2007-09-08 Thread Jim Price

# Create a matrix of ball locations
# You'd do this using the calls within your points function
balls - matrix(c(0,50,25,-150,-100,-50), ncol=2, byrow=F)


# Draw a line from the origin to each ball location
apply(balls, 1, function(x) lines(c(125, x[1]), c(-210, x[2]), col='red'))



A more complete example might loop over all the unique elements of
framename$hit_traj, and then run this procedure for each value with a
different colour, plotting both ball points and trajectories.



lawnboy34 wrote:
 
 I am using R to plot baseball spray charts from play-by-play data. I have
 used the following command to plot the diamond:
 
 plot (0:250, -250:0, type=n, bg=white)
   lines(c(125,150,125,100,125),c(-210,-180,-150,-180,-210), 
 col=c(black))
 
 I have also plotted different hit locations using commands such as the
 following:
 
 points(subset(framename$hit_x, framename$hit_traj==line_drive),
 subset(-framename$hit_y, framename$hit_traj==line_drive), pch=20,
 col=c(red))
 
 My question: Is there any easy way to plot a line from the origin (home
 plate) to each point on the graph? Preferably the line would share the
 same color as the dot that denotes where the ball landed. I have tried
 searching Google and these forums, and most graphing questions have to do
 with scatterplots or other varieties of graphs I am not using. Thanks very
 much in advance.
 
 -Jason
 

-- 
View this message in context: 
http://www.nabble.com/Plotting-lines-to-sets-of-points-tf4404235.html#a12564959
Sent from the R help mailing list archive at Nabble.com.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Plotting lines to sets of points

2007-09-07 Thread lawnboy34

I am using R to plot baseball spray charts from play-by-play data. I have
used the following command to plot the diamond:

plot (0:250, -250:0, type=n, bg=white)
lines(c(125,150,125,100,125),c(-210,-180,-150,-180,-210), 
col=c(black))

I have also plotted different hit locations using commands such as the
following:

points(subset(framename$hit_x, framename$hit_traj==line_drive),
subset(-framename$hit_y, framename$hit_traj==line_drive), pch=20,
col=c(red))

My question: Is there any easy way to plot a line from the origin (home
plate) to each point on the graph? Preferably the line would share the same
color as the dot that denotes where the ball landed. I have tried searching
Google and these forums, and most graphing questions have to do with
scatterplots or other varieties of graphs I am not using. Thanks very much
in advance.

-Jason
-- 
View this message in context: 
http://www.nabble.com/Plotting-lines-to-sets-of-points-tf4404235.html#a12564704
Sent from the R help mailing list archive at Nabble.com.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plotting lines to sets of points

2007-09-07 Thread jim holtman
?segments

On 9/7/07, lawnboy34 [EMAIL PROTECTED] wrote:

 I am using R to plot baseball spray charts from play-by-play data. I have
 used the following command to plot the diamond:

 plot (0:250, -250:0, type=n, bg=white)
lines(c(125,150,125,100,125),c(-210,-180,-150,-180,-210), 
 col=c(black))

 I have also plotted different hit locations using commands such as the
 following:

 points(subset(framename$hit_x, framename$hit_traj==line_drive),
 subset(-framename$hit_y, framename$hit_traj==line_drive), pch=20,
 col=c(red))

 My question: Is there any easy way to plot a line from the origin (home
 plate) to each point on the graph? Preferably the line would share the same
 color as the dot that denotes where the ball landed. I have tried searching
 Google and these forums, and most graphing questions have to do with
 scatterplots or other varieties of graphs I am not using. Thanks very much
 in advance.

 -Jason
 --
 View this message in context: 
 http://www.nabble.com/Plotting-lines-to-sets-of-points-tf4404235.html#a12564704
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.