[R] plot pch

Peter Ehlers ehlers at ucalgary.ca
Mon Mar 11 23:45:28 CET 2013


On 2013-03-11 14:59, eliza botto wrote:
>
> Thankyou very much rui.i was trying the following command but i was unsuccessful in implementing the secondary axis.
>> library(lattice)> df <- data.frame(x = x, y = y, z= z)> > xyplot(x~y,data=df,groups=z,+        par.settings=list(superpose.symbol=list(pch=1:4,+                                                col='black')))
> By the way, is there a way that instead of making a separate secondary axis, we could put a small classification number on the top of every symbol?? Thankyou very much for helping me out....
> Elisa

Using Rui's dataframe 'dat' and pch-vector 'ch':

   with(dat, plot(x, y, pch = ch[z]))
   with(dat, text(x, y, lab=z, pos=3, cex=.7))

Try also pos=1,2,4 to see what suits you best.

Peter Ehlers

>> Date: Mon, 11 Mar 2013 21:33:33 +0000
>> From: ruipbarradas at sapo.pt
>> To: eliza_botto at hotmail.com
>> CC: r-help at r-project.org
>> Subject: Re: [R] plot pch
>>
>> Hello,
>>
>> Try the following.
>>
>> dat <-
>> structure(list(x = c(52.5211966906669, 49.8818953734405, 45.176643179385,
>> 52.2988909042952, 46.1007828702965, 53.4910266471472, 49.013651970548,
>> 55.1218462810432, 56.922347550005, 50.7531277271902), y =
>> c(23.953008533893,
>> 45.1590889001506, 62.5358474328017, 39.4861634272874, 49.3108455233261,
>> 46.0010163238786, 46.5779093951996, 37.4552698003145, 46.4057156535496,
>> 56.667549695452), z = c(1, 4, 1, 2, 1, 3, 4, 2, 1, 3), r = 1:10), .Names
>> = c("x",
>> "y", "z", "r"), row.names = c(NA, -10L), class = "data.frame")
>>
>> ch <- c(2, 22, 5, 1, 4)  # triangle, rectangle, rhombus, circle, cross.
>> plot(dat$x, dat$y, pch = ch[dat$z])
>> axis(4, at = dat$y, labels = seq_along(dat$y)[order(dat$y)])
>>
>>
>> Also, if you want to see the pch characters, run without worrying about
>> the warnings (in general a bad tip, not really important here)
>>
>> plot(1, type = "n", xlim=c(0, 17), ylim=c(0, 17))
>> for(x in 1:16) for(y in 1:16)
>> 	points(x, y, pch = (x - 1)*16 + y)
>>
>>
>> They go first column with x = 1, from y = 1 to 16, etc.
>>
>>
>> Hope this helps,
>>
>> Rui Barradas
>>
>> Em 11-03-2013 17:43, eliza botto escreveu:
>>>
>>> Dear xpeRts,
>>>
>>> I would like to ask a question about plotting in R.
>>> I have four columns in which first column contains x-coordinate and second column contains y-coordinate of certain points, whereas the third column "z" contains classification number of those points from 1 to 4, it should be noted that this column doesn't quantify anything, but just classify the points. More precisely like the following
>>>
>>>
>>>> dput(v)
>>>
>>>
>>> structure(list(x = c(52.5211966906669, 49.8818953734405, 45.176643179385,
>>> 52.2988909042952, 46.1007828702965, 53.4910266471472, 49.013651970548,
>>> 55.1218462810432, 56.922347550005, 50.7531277271902), y = c(23.953008533893,
>>> 45.1590889001506, 62.5358474328017, 39.4861634272874, 49.3108455233261,
>>> 46.0010163238786, 46.5779093951996, 37.4552698003145, 46.4057156535496,
>>> 56.667549695452), z = c(1, 4, 1, 2, 1, 3, 4, 2, 1, 3), r = 1:10), .Names = c("x",
>>> "y", "z", "r"), row.names = c(NA, -10L), class = "data.frame")
>>>
>>>
>>> What i want to do is to locate, in the space of "x" and "y", each point (in classified section) with different shape for each classified section range from 1 to 4, by command "pch".
>>> There should also be a y-axis on the right end of x-axis (secondary axis), which carries the the point number as in column "r". As there are ten points so that axis should range to 10 for the presentation of each point number. More precisely, z=1 should be located at a point where x=52.52120, y=23.95301 and r=1.
>>> where,
>>> x= x-axis
>>>
>>> y=y-axis on the left end of x-axis
>>>
>>> r=y-axis on the right end of x-axis (secondary axis)
>>>
>>> For points belonging to classification 1 there should be a triangle
>>> For points belonging to classification 2 there should be a rectangle
>>> and so on...
>>> in my orinigal data i have 5 classifications.
>>>
>>> i hope i was clear, but in case i my wording is confusing, kindly let me know.
>>>
>>> Elisa
>>>    		 	   		
>>> 	[[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> 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.
>>>
>   		 	   		
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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