# 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.

Reply via email to