[R] putting circles/buffers arround points on a 2D graph/plot

Albyn Jones jones at reed.edu
Thu Jul 16 20:49:13 CEST 2009


It sounds like you might want to draw the convex hull for each group
of points.  There is a package called "chplot" which appears to
do this, though I haven't used it...

albyn

On Thu, Jul 16, 2009 at 06:23:54PM +0100, Ahmed, Sadia wrote:
> Hi, 
> 
> I'll try to keep my question brief and to the point, to anyone who helps 'THANK YOU!'
> 
> I want to get a circle/ring/buffer or some other form of drawn line around certain points on a x,y plot, the points usually don't form a circle, often they form a 'wobbly' shape, so ideally I'd like something that follows the shape the points make.
> 
> I'll start by explaining what I've got (I'm sorry if it's a little long, but it's all important for explaining what I want to do):
> 
> I have a simple 2D plot of an x variable, called 'percent.forest'', and a y variable called 'metric'. the data for this plot is in a large data frame with a third variable called 'Buffer', there are 5 buffer sizes (250, 500, 1000, 3000, 10000).
> 
> to create the plot I simply used 
> >plot(percent.forest,metric)
> 
> to add in the data about buffer size, I have extracted the percent forest and metric data by:
> >buff250<-subset(data1,data1$Buffer==250)
> >buff500<-subset(data1,data1$Buffer==500)
> >buff1000<-subset(data1,data1$Buffer==1000)
> >buff3000<-subset(data1,data1$Buffer==3000)
> >buff10000<-subset(data1,data1$Buffer==10000)
> 
> i then used the 'points' function to plot the percent forest, metric data points in different colours according to buffer size, using this code (first 2 lines divides the data appropriately, 3rd line is points):
> >metric.250<-(log(buff250$metric))
> >percent.forest.250<-(buff250$percent.forest)
> >points(percent.forest.250,metric.250,col='skyblue')
> 
> I repeated this for all 5 buffer sizes, so on the plot (percent.forest,metric) the points are coloured differently according to the size of the buffer used.
> This works fine (the next bit is the problem):
> 
> Does anyone know how I can get R to draw around the different coloured points, so that i get 5 rings/wiggly lines on the plot that clearly shows the extent of each of the buffers, you can sort of see a pattern in the colours but its not as clear as it would be if I could draw around it). 
> 
> If anyone wants to see a picture of the plot (if my explanation isn't clear enough) I'd be happy to email one directly to you (the R instructions says that the mailing list scraps attachments so I've not put one on here)
> 
> Thank you for reading this, 
> Any help will be greatly appreciated,
> sadia  
> 
> ______________________________________________
> R-help at r-project.org 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.
>




More information about the R-help mailing list