[R] Fwd: Need help with xyplot - thanks
aziz4 at illinois.edu
aziz4 at illinois.edu
Tue Aug 9 20:33:24 CEST 2011
Very interesting. I can track every person along the lines too. It would be useful to have a grouping on Age-range as my actual data has above six thousand nodes and thus the spaghetti can get really messy. I shall get back with more questions after some trials with your code.
Best,
Fayez
---- Original message ----
>Date: Tue, 09 Aug 2011 20:48:03 +1000
>From: Jim Lemon <jim at bitwrit.com.au>
>Subject: Re: [R] Fwd: Need help with xyplot
>To: aziz4 at illinois.edu
>Cc: r-help at r-project.org
>
>On 08/09/2011 03:10 AM, aziz4 at illinois.edu wrote:
>>
>>
>> ---- Original message ----
>>> Date: Wed, 3 Aug 2011 16:06:33 -0500 (CDT)
>>> From:<aziz4 at illinois.edu>
>>> Subject: Need help with xyplot
>>> To: r-help at r-project.org
>>>
>>>
>>> Consider I have the following data:
>>>
>>> AgeRange AgeOfPerson PersonNo FriendsAtYear0 FriendsAtYear1 FriendsAtYear2 FriendsAtYear3 FriendsAtYear4 FriendsAtYear5
>>> 10 - 12 11 1 0 1 2 2 3 3
>>> 10 - 12 12 2 0 1 2 2 3 3
>>> 15 - 18 13 3 1 2 3 4 6 7
>>> 15 - 18 14 4 1 3 4 5 7 7
>>> 30 - 40 33 5 3 5 5 6 8 9
>>> 30 - 40 36 6 4 4 4 4 4 4
>>>
>>> I want to plot the number of friends against number of years, as to show how friendships grew over time. Also, I want to group the graphs by AgeRange of persons and also color them with respect to the Age of Persons. So far, I have this code:
>>>
>>>
>>> FilePath = "C:\\Documents and Settings\\All Users\\Documents\\Desktop\\Fayez\\ResearchWork\\Pajek_Work\\Program\\2011-03-07-Wed-FriMeetingApr15\\RPractice\\"
>>>
>>> NumberOfyears<- c(0, 1, 2, 3, 4 ,5);
>>>
>>> File2Open = paste(FilePath, "FriendshipNetExample.txt", sep = "")
>>> # print(File2Open)
>>>
>>> DataTable = read.table(File2Open, header = TRUE, sep = "\t")
>>> # print(DataTable)
>>>
>>> print(xyplot(FriendsAtYear0 + FriendsAtYear1 + FriendsAtYear2 + FriendsAtYear3 + FriendsAtYear4 + FriendsAtYear5
>>> ~ AgeOfPerson | AgeRange, data = DataTable, xlab = "Number of Years (0 to 5)", ylab = "Number of Friends", main = "Number of Friends vs. Years",
>>> #aspect = "xy", # calculate an optimal aspect ratio
>>> panel = function(x,y) {
>>> panel.grid();
>>> if (10<= x&& x< 12) panel.xyplot(x,y,col="red");
>>> if (15<= x&& x< 18) panel.xyplot(x,y,col="salmon");
>>> if (30<= x&& x< 40) panel.xyplot(x,y,col="maroon");
>>> } ) )
>>>
>>> But it obviously does not serve the purpose. Urgent help would be most appreciated.
>>>
>Hi Fayez,
>I would suggest a "spaghetti plot" where multiple lines track the number
>of friends over time. This may give you some ideas:
>
>library(plotrix)
>friends<-read.table("friends.tab",sep="\t",header=TRUE)
>matplot(friends[,4:9],col=color.scale(friends[,2],extremes=c(3,2)),
> type="b",main="Friends by time",xlab="Year",ylab="Number of friends")
>
>Jim
More information about the R-help
mailing list