[R] plot pch

Rui Barradas ruipbarradas at sapo.pt
Mon Mar 11 22:33:33 CET 2013


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



More information about the R-help mailing list