---- Original message ---- >Date: Wed, 3 Aug 2011 16:06:33 -0500 (CDT) >From: <az...@illinois.edu> >Subject: Need help with xyplot >To: r-help@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. > >Best, >Fayez >Grad student - UIUC
______________________________________________ R-help@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.