Advertisement
tomsim

Plot data with group symbol

Aug 17th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.07 KB | None | 0 0
  1. # Plot data by group symbol
  2. # plot data has time, record number and site count, POT group
  3. # Create grpName from data field and add it back
  4. grpName = as.character(plotData$SITE_COUNT)
  5. grpName = paste(grpName, plotData$POT, sep=';')
  6. plotData$grpName = grpName
  7. # Create main plot data
  8. pplotData = data.frame(yValue=plotData$idleTime,
  9.     xValue=plotData$recNum, grpName=plotData$grpName,
  10.     class=array(length(plotData$grpName)))
  11. # Create a list of all unique group names and assign index to them by alphabetical order
  12. grpFactor = as.factor(sort(unique(pplotData$grpName)))
  13. # index the factor names
  14. grpIdxList = c(grpFactor)
  15. grpList = levels(grpFactor)
  16. # Set class id for each group
  17. for( grpIdx in grpIdxList)
  18. {
  19.     grpName = grpList[grpIdx]
  20.     pplotData$class[pplotData$grpName == grpName] = grpIdx
  21. }
  22. symIdx = pplotData$class
  23. # Plot data with each point colored by the group index.
  24. # Make the ploting symbol a little bigger with cex parameter
  25. plot( pplotData$xValue, pplotData$yValue, pch=symIdx, col=(symIdx+1), cex=1.2,
  26.     main="plot title",xlab="x label", ylab="Y label")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement