[R] Customise a symbol in a scatterplot with for loop
Jim Lemon
jim at bitwrit.com.au
Sun Mar 23 23:43:50 CET 2014
On 03/24/2014 07:00 AM, amcc wrote:
> Hi,
> I have the code below to generate a pentagon in R. I have generated a
> regular scatterplot and need to draw a scatterplot with a pentagon at each
> (x,y) position, for the radius use r x 0.3. The hint I've been given is
> that I do not need to store the polygons in a list, simply construct and
> draw the polygons within a for loop. Four hours have gone by and I'm no
> closer, so any help would be appreciated. My original scatterplot code is
>
> plot(Sepal.Width~Sepal.Length, data=iriss)
>
> mk_pent<-
> function(x,y,r){
> angle<-(0:4)*360/5+90
> angle<-angle*pi/180
> xs<-r*cos(angle)+x
> ys<-r*sin(angle)+y
> cbind(x=xs,y=ys)}
Hi A,
Your function is almost there, it just doesn't close the pentagon. You
might think of drawing the lines within the function to make things
easier. Once you can successfully draw a pentagon on an existing plot,
you can work out how to pass your x and y coordinates successively to it
within the for loop.
Jim
More information about the R-help
mailing list