[R] Plotting lines to sets of points

S Ellison S.Ellison at lgc.co.uk
Mon Sep 10 13:05:20 CEST 2007


see ?segments. 

And you can tidy up your subsetting with some with's while you're at it, although a function would be nicer still.

Looking at your code, you probably need something like

with(subset(framename, hit_traj=="line_drive"),
	segments(rep(125,length(hit_x)) , rep(-210,length(hit_y)), hit_x, hit_y, col="blue")
) #You can put it all on one line for convenience of repetition but its not as readable

with(subset(framename, hit_traj=="line_drive"),
	points(hit_x, hit_y, pch=20, col="red")
)


btw: seems an odd coordinate system. Why not put the hitter at the origin?




Steve E

>>> lawnboy34 <jay.pare at gmail.com> 08/09/2007 00:01:22 >>>

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

*******************************************************************
This email and any attachments are confidential. Any use, co...{{dropped}}



More information about the R-help mailing list