| 227 | | ## @classmethod |
| 228 | | ## def ClevelandPlotForArcGISTable(cls, table, fields=None, transforms=None, orderByField=None, where=None, |
| 229 | | ## xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None, |
| 230 | | ## outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False): |
| 231 | | ## cls.__doc__.Obj.ValidateMethodInvocation() |
| 232 | | ## |
| 233 | | ## # Load the data frame into a temporary data frame. |
| 234 | | ## |
| 235 | | ## r = R.GetInterpreter() |
| 236 | | ## transformsName = R.GetUniqueVariableName() |
| 237 | | ## dataFrameName = R.GetUniqueVariableName() |
| 238 | | ## R.LoadDataFrameFromArcGISTable(table, dataFrameName, where=where, fields=fields, xColumnName=xColumnName, yColumnName=yColumnName, zColumnName=zColumnName, mColumnName=mColumnName) |
| 239 | | ## |
| 240 | | ## # Create the plot. |
| 241 | | ## |
| 242 | | ## try: |
| 243 | | ## if r('length(%s)' % dataFrameName) <= 0: |
| 244 | | ## if where is not None: |
| 245 | | ## Logger.RaiseException(ValueError(_(u'The where clause "%(where)s" did not select any rows from the table %(table)s.') % {u'table': table, u'where': where})) |
| 246 | | ## else: |
| 247 | | ## Logger.RaiseException(ValueError(_(u'The table %(table)s is empty.') % {u'table': table})) |
| 248 | | ## |
| 249 | | ## if transforms is not None and len(transforms) > 0: |
| 250 | | ## if len(transforms) > len(fields): |
| 251 | | ## transforms = transforms[:len(fields)] |
| 252 | | ## r[transformsName] = dict(zip(fields[:len(transforms)], transforms)) |
| 253 | | ## else: |
| 254 | | ## r('%s <- NULL' % transformsName) |
| 255 | | ## |
| 256 | | ## # TODO: Sort |
| 257 | | ## |
| 258 | | ## r('library(lattice)') |
| 259 | | ## #r('foobar <<- cbind(%s$wincrd, %s$tarsus)' % (dataFrameName, dataFrameName)) |
| 260 | | ## r('zz <- VADeaths') |
| 261 | | ## r('dotplot(zz)') |
| 262 | | ## |
| 263 | | #### R.EvaluateFile(os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), 'ClevelandPlotForDataframe.r'), False) |
| 264 | | #### if outputFile is None: |
| 265 | | #### r('ClevelandPlot(%s, transforms=%s)' % (dataFrameName, transformsName)) |
| 266 | | #### else: |
| 267 | | #### Logger.Info(_(u'Writing scatterplot matrix to %(file)s...') % {u'file': outputFile}) |
| 268 | | #### r('ClevelandPlotToFile("%s", %s, transforms=%s, res=%f, width=%f, height=%f, pointSize=%f, bg="%s")' % (outputFile.replace(u'\\', u'/'), dataFrameName, transformsName, str(diagonal), str(lower), str(upper), res, width, height, pointSize, bg)) |
| 269 | | ## |
| 270 | | ## # Delete the data frame. |
| 271 | | ## |
| 272 | | ## finally: |
| 273 | | ## r('if (exists("%s")) rm("%s")' % (transformsName, transformsName)) |
| 274 | | ## r('if (exists("%s")) rm("%s")' % (dataFrameName, dataFrameName)) |
| | 227 | @classmethod |
| | 228 | def ClevelandPlotForArcGISTable(cls, table, fields=None, transforms=None, orderByField=None, where=None, |
| | 229 | xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None, |
| | 230 | outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False): |
| | 231 | cls.__doc__.Obj.ValidateMethodInvocation() |
| | 232 | |
| | 233 | # Load the data frame into a temporary data frame. |
| | 234 | |
| | 235 | if orderByField is not None: |
| | 236 | if fields is None: |
| | 237 | fields = [] |
| | 238 | if orderByField not in fields: |
| | 239 | fields.append(orderByField) |
| | 240 | |
| | 241 | r = R.GetInterpreter() |
| | 242 | transformsName = R.GetUniqueVariableName() |
| | 243 | dataFrameName = R.GetUniqueVariableName() |
| | 244 | R.LoadDataFrameFromArcGISTable(table, dataFrameName, where=where, fields=fields, xColumnName=xColumnName, yColumnName=yColumnName, zColumnName=zColumnName, mColumnName=mColumnName) |
| | 245 | |
| | 246 | # Create the plot. |
| | 247 | |
| | 248 | try: |
| | 249 | if r('length(%s)' % dataFrameName) <= 0: |
| | 250 | if where is not None: |
| | 251 | Logger.RaiseException(ValueError(_(u'The where clause "%(where)s" did not select any rows from the table %(table)s.') % {u'table': table, u'where': where})) |
| | 252 | else: |
| | 253 | Logger.RaiseException(ValueError(_(u'The table %(table)s is empty.') % {u'table': table})) |
| | 254 | |
| | 255 | if transforms is not None and len(transforms) > 0: |
| | 256 | if len(transforms) > len(fields): |
| | 257 | transforms = transforms[:len(fields)] |
| | 258 | r[transformsName] = dict(zip(fields[:len(transforms)], transforms)) |
| | 259 | else: |
| | 260 | r('%s <- NULL' % transformsName) |
| | 261 | |
| | 262 | if orderByField is not None: |
| | 263 | r('%s <- %s[order(%s$%s),]' % (dataFrameName, dataFrameName, dataFrameName, orderByField)) |
| | 264 | |
| | 265 | R.EvaluateFile(os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), 'ClevelandPlotForDataframe.r'), False) |
| | 266 | if outputFile is None: |
| | 267 | r('ClevelandPlot(%s, transforms=%s)' % (dataFrameName, transformsName)) |
| | 268 | else: |
| | 269 | Logger.Info(_(u'Writing scatterplot matrix to %(file)s...') % {u'file': outputFile}) |
| | 270 | r('ClevelandPlotToFile("%s", %s, transforms=%s, res=%f, width=%f, height=%f, pointSize=%f, bg="%s")' % (outputFile.replace(u'\\', u'/'), dataFrameName, transformsName, res, width, height, pointSize, bg)) |
| | 271 | |
| | 272 | # Delete the data frame. |
| | 273 | |
| | 274 | finally: |
| | 275 | r('if (exists("%s")) rm("%s")' % (transformsName, transformsName)) |
| | 276 | r('if (exists("%s")) rm("%s")' % (dataFrameName, dataFrameName)) |
| 709 | | ### Public method: RExploratoryPlots.ClevelandPlotForArcGISTable |
| 710 | | ## |
| 711 | | ##AddMethodMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable, |
| 712 | | ## shortDescription=_(u'Creates a multi-panel Cleveland dotplot for a table.'), |
| 713 | | ## longDescription=_( |
| 714 | | ##u"""Cleveland dotplots (Cleveland 1993) are typically used to detect |
| 715 | | ##possible outliers. Each dotplot shows the row number of the record vs. |
| 716 | | ##the value of a field. Points that appear far to the left or right are |
| 717 | | ##extreme values of that field and may be statistical outliers that |
| 718 | | ##should be investigated and possibly removed prior to further analysis |
| 719 | | ##of the data. |
| 720 | | ## |
| 721 | | ##For advice on how to use Cleveland dotplots, please see Zuur et al. |
| 722 | | ##(2009). |
| 723 | | ## |
| 724 | | ##**References:** |
| 725 | | ## |
| 726 | | ##Cleveland, W.S. (1993) Visualizing Data. Hobart Press, Summit, NJ. |
| 727 | | ## |
| 728 | | ##Zuur, A.F., Ineo, E.N., Elphick, C.S. (2009) A protocol for data |
| 729 | | ##exploration to avoid common statistical problems. Methods in Ecology & |
| 730 | | ##Evolution 1: 3-14."""), |
| 731 | | ## isExposedToPythonCallers=True, |
| 732 | | ## isExposedByCOM=True, |
| 733 | | ## isExposedAsArcGISTool=True, |
| 734 | | ## arcGISDisplayName=_(u'Cleveland Plot for Table'), |
| 735 | | ## arcGISToolCategory=_(u'Statistics\\Explore Data'), |
| 736 | | ## dependencies=[ArcGISDependency(9, 1), RDependency(2, 5, 0)]) |
| 737 | | ## |
| 738 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'cls', RExploratoryPlots.ClevelandPlotForArcGISTable, u'cls') |
| 739 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'table', RExploratoryPlots.ClevelandPlotForArcGISTable, u'table') |
| 740 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'fields', RExploratoryPlots.ClevelandPlotForArcGISTable, u'fields') |
| 741 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'transforms', RExploratoryPlots.ClevelandPlotForArcGISTable, u'transforms') |
| 742 | | ## |
| 743 | | ##AddArgumentMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable, u'orderByField', |
| 744 | | ## typeMetadata=ArcGISFieldTypeMetadata(mustExist=True, allowedFieldTypes=[u'SHORT', u'LONG', u'FLOAT', u'DOUBLE', u'TEXT', u'DATE'], canBeNone=True), |
| 745 | | ## description=_( |
| 746 | | ##u"""Field specifying how the data will be ordered on the y axis of the |
| 747 | | ##plots. |
| 748 | | ## |
| 749 | | ##This parameter is optional and provided to enhance readability when |
| 750 | | ##the plotted fields' values correlate with another field. For example, |
| 751 | | ##if the weight and size of an animal correlate with the animal's age, |
| 752 | | ##you could order the plots by age and the weight and size points would |
| 753 | | ##cluster around a trend line rather than being randomly dispersed. This |
| 754 | | ##may aid in the visual identification of possible outliers."""), |
| 755 | | ## arcGISParameterDependencies=[u'table'], |
| 756 | | ## arcGISDisplayName=_(u'Order by field')) |
| 757 | | ## |
| 758 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'where', RExploratoryPlots.ClevelandPlotForArcGISTable, u'where') |
| 759 | | ## |
| 760 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'xColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'xColumnName') |
| 761 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'yColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'yColumnName') |
| 762 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'zColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'zColumnName') |
| 763 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'mColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'mColumnName') |
| 764 | | ## |
| 765 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'outputFile', RExploratoryPlots.ClevelandPlotForArcGISTable, u'outputFile') |
| 766 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'res', RExploratoryPlots.ClevelandPlotForArcGISTable, u'res') |
| 767 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'width', RExploratoryPlots.ClevelandPlotForArcGISTable, u'width') |
| 768 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'height', RExploratoryPlots.ClevelandPlotForArcGISTable, u'height') |
| 769 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'pointSize', RExploratoryPlots.ClevelandPlotForArcGISTable, u'pointSize') |
| 770 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'bg', RExploratoryPlots.ClevelandPlotForArcGISTable, u'bg') |
| 771 | | ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'overwriteExisting', RExploratoryPlots.ClevelandPlotForArcGISTable, u'overwriteExisting') |
| | 711 | # Public method: RExploratoryPlots.ClevelandPlotForArcGISTable |
| | 712 | |
| | 713 | AddMethodMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable, |
| | 714 | shortDescription=_(u'Creates a multi-panel Cleveland dotplot for a table.'), |
| | 715 | longDescription=_( |
| | 716 | u"""Cleveland dotplots (Cleveland 1993) are typically used to explore |
| | 717 | the distributions of values in a table and detect possible outliers. |
| | 718 | Each dotplot shows the row number of the record vs. the value of a |
| | 719 | field. Points that appear far to the left or right are extreme values |
| | 720 | of that field and may be statistical outliers that should be |
| | 721 | investigated and possibly removed prior to further analysis of the |
| | 722 | data. |
| | 723 | |
| | 724 | For advice on how to use Cleveland dotplots, please see Zuur et al. |
| | 725 | (2009). |
| | 726 | |
| | 727 | **References:** |
| | 728 | |
| | 729 | Cleveland, W.S. (1993) Visualizing Data. Hobart Press, Summit, NJ. |
| | 730 | |
| | 731 | Zuur, A.F., Ineo, E.N., Elphick, C.S. (2009) A protocol for data |
| | 732 | exploration to avoid common statistical problems. Methods in Ecology & |
| | 733 | Evolution 1: 3-14."""), |
| | 734 | isExposedToPythonCallers=True, |
| | 735 | isExposedByCOM=True, |
| | 736 | isExposedAsArcGISTool=True, |
| | 737 | arcGISDisplayName=_(u'Cleveland Plot for Table'), |
| | 738 | arcGISToolCategory=_(u'Statistics\\Explore Data'), |
| | 739 | dependencies=[ArcGISDependency(9, 1), RDependency(2, 5, 0)]) |
| | 740 | |
| | 741 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'cls', RExploratoryPlots.ClevelandPlotForArcGISTable, u'cls') |
| | 742 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'table', RExploratoryPlots.ClevelandPlotForArcGISTable, u'table') |
| | 743 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'fields', RExploratoryPlots.ClevelandPlotForArcGISTable, u'fields') |
| | 744 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'transforms', RExploratoryPlots.ClevelandPlotForArcGISTable, u'transforms') |
| | 745 | |
| | 746 | AddArgumentMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable, u'orderByField', |
| | 747 | typeMetadata=ArcGISFieldTypeMetadata(mustExist=True, allowedFieldTypes=[u'SHORT', u'LONG', u'FLOAT', u'DOUBLE', u'TEXT', u'DATE'], canBeNone=True), |
| | 748 | description=_( |
| | 749 | u"""Field specifying how the data will be ordered on the y axis of the |
| | 750 | plots. |
| | 751 | |
| | 752 | This parameter is optional and provided to enhance readability when |
| | 753 | the plotted fields' values correlate with another field. For example, |
| | 754 | if the weight and size of an animal correlate with the animal's age, |
| | 755 | you could order the plots by age and the weight and size points would |
| | 756 | cluster around a trend line rather than being randomly dispersed. This |
| | 757 | may aid in the visual identification of possible outliers."""), |
| | 758 | arcGISParameterDependencies=[u'table'], |
| | 759 | arcGISDisplayName=_(u'Order by field')) |
| | 760 | |
| | 761 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'where', RExploratoryPlots.ClevelandPlotForArcGISTable, u'where') |
| | 762 | |
| | 763 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'xColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'xColumnName') |
| | 764 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'yColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'yColumnName') |
| | 765 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'zColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'zColumnName') |
| | 766 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'mColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'mColumnName') |
| | 767 | |
| | 768 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'outputFile', RExploratoryPlots.ClevelandPlotForArcGISTable, u'outputFile') |
| | 769 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'res', RExploratoryPlots.ClevelandPlotForArcGISTable, u'res') |
| | 770 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'width', RExploratoryPlots.ClevelandPlotForArcGISTable, u'width') |
| | 771 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'height', RExploratoryPlots.ClevelandPlotForArcGISTable, u'height') |
| | 772 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'pointSize', RExploratoryPlots.ClevelandPlotForArcGISTable, u'pointSize') |
| | 773 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'bg', RExploratoryPlots.ClevelandPlotForArcGISTable, u'bg') |
| | 774 | CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'overwriteExisting', RExploratoryPlots.ClevelandPlotForArcGISTable, u'overwriteExisting') |