Browse files

merge hadley/develop into kohske/feature/new-guides

  • Loading branch information...
2 parents 16b71cf + ffea2ec commit a6725c19e81af8233c8c24cb28bded52355b4a63 @kohske kohske committed May 25, 2011
Showing with 3,636 additions and 2,178 deletions.
  1. +164 −53 DESCRIPTION
  2. +93 −23 NAMESPACE
  3. +48 −3 NEWS
  4. +1 −1 R/aes.r
  5. +24 −0 R/bench.r
  6. +71 −64 R/coord-.r
  7. +60 −70 R/coord-cartesian-.r
  8. +0 −69 R/coord-cartesian-flipped.r
  9. +9 −13 R/{coord-cartesian-equal.r → coord-fixed.r}
  10. +68 −0 R/coord-flip.r
  11. +119 −122 R/coord-map.r
  12. +20 −0 R/coord-munch.r
  13. +164 −161 R/coord-polar.r
  14. +62 −70 R/coord-transform.r
  15. +50 −24 R/facet-.r
  16. +182 −302 R/facet-grid-.r
  17. +7 −7 R/facet-labels.r
  18. +131 −0 R/facet-layout.r
  19. +71 −0 R/facet-locate.r
  20. +70 −0 R/facet-null.r
  21. +159 −259 R/facet-wrap.r
  22. +7 −4 R/fortify-lm.r
  23. +5 −0 R/fortify-map.r
  24. +2 −1 R/geom-abline.r
  25. +2 −2 R/geom-bar-.r
  26. +6 −5 R/geom-bin2d.r
  27. +1 −1 R/geom-error.r
  28. +1 −1 R/geom-hex.r
  29. +1 −1 R/geom-linerange.r
  30. +6 −3 R/geom-path-.r
  31. +1 −1 R/geom-path-contour.r
  32. +3 −2 R/geom-path-line.r
  33. +2 −2 R/geom-point-.r
  34. +1 −1 R/geom-polygon.r
  35. +2 −2 R/geom-rect.r
  36. +3 −1 R/geom-ribbon-.r
  37. +1 −1 R/geom-rug.r
  38. +9 −6 R/geom-segment.r
  39. +15 −5 R/geom-text.r
  40. +1 −1 R/geom-tile.r
  41. +1 −1 R/ggplot2.r
  42. +2 −2 R/grob-absolute.r
  43. +0 −242 R/grob-grid.r
  44. +1 −1 R/grob-null.r
  45. +1 −0 R/labels.r
  46. +35 −114 R/layer.r
  47. +70 −57 R/limits.r
  48. +195 −0 R/panel.r
  49. +48 −28 R/plot-build.r
  50. +7 −5 R/plot-construction.r
  51. +31 −31 R/plot-render.r
  52. +2 −3 R/plot.r
  53. +2 −0 R/position-collide.r
  54. +1 −1 R/position-dodge.r
  55. +3 −5 R/position-fill.r
  56. +1 −1 R/position-jitter.r
  57. +1 −1 R/position-stack.r
  58. +4 −2 R/quick-plot.r
  59. +49 −8 R/scale-.r
  60. +3 −2 R/scale-alpha.r
  61. +1 −1 R/scale-brewer.r
  62. +13 −14 R/scale-continuous.r
  63. +3 −4 R/scale-date.r
  64. +1 −1 R/scale-datetime.r
  65. +21 −3 R/scale-discrete-.r
  66. +12 −5 R/scale-gradient.r
  67. +14 −6 R/scale-gradient2.r
  68. +12 −10 R/scale-gradientn.r
  69. +14 −4 R/scale-grey.r
  70. +14 −4 R/scale-hue.r
  71. +21 −6 R/scale-identity.r
  72. +3 −3 R/scale-linetype.r
  73. +5 −0 R/scale-manual.r
  74. +1 −1 R/scale-shape.r
  75. +4 −4 R/scale-size.r
  76. +5 −1 R/scales-.r
  77. +1 −1 R/stat-bin.r
  78. +2 −2 R/stat-bin2d.r
  79. +2 −2 R/stat-binhex.r
  80. +5 −5 R/stat-boxplot.r
  81. +2 −2 R/stat-contour.r
  82. +1 −1 R/stat-density-2d.r
  83. +2 −2 R/stat-density.r
  84. +1 −1 R/stat-function.r
  85. +1 −1 R/stat-qq.r
  86. +2 −2 R/stat-smooth.r
  87. +5 −8 R/stat-sum.r
  88. +1 −1 R/stat-summary.r
  89. +1 −1 R/summary.r
  90. +1 −0 R/templates.r
  91. +1 −4 R/theme.r
  92. +21 −26 R/utilities-break.r
  93. +9 −4 R/utilities-colour.r
  94. +23 −0 R/utilities-grid.r
  95. +8 −34 R/utilities-layer.r
  96. +46 −0 R/utilities-table-template.r
  97. +292 −0 R/utilities-table.r
  98. +8 −4 R/utilities.r
  99. +2 −2 R/xxx-codegen.r
  100. +0 −8 R/xxx.r
  101. +16 −8 R/zxx.r
  102. +17 −3 README.md
  103. +28 −0 inst/tests/helper-plot-data.r
  104. +37 −0 inst/tests/test-aes-grouping.r
  105. +34 −7 inst/tests/test-build.r
  106. +59 −0 inst/tests/test-facet-.r
  107. +81 −0 inst/tests/test-facet-layout.r
  108. +61 −0 inst/tests/test-facet-locate.r
  109. +54 −0 inst/tests/test-scales.r
  110. +126 −0 inst/tests/test-table-layout.r
  111. +0 −4 man/as.list.unit.Rd
  112. +15 −0 man/benchplot.Rd
  113. +0 −4 man/cbind.grobGrid.Rd
  114. +0 −7 man/continuous_scale.Rd
  115. +16 −0 man/coord.Rd
  116. +1 −0 man/{coord_cartesian.rd → coord_cartesian.Rd}
  117. +1 −0 man/{coord_fixed.rd → coord_fixed.Rd}
  118. +6 −3 man/{coord_flip.rd → coord_flip.Rd}
  119. +5 −2 man/{coord_map.rd → coord_map.Rd}
  120. +1 −0 man/{coord_polar.rd → coord_polar.Rd}
  121. +12 −2 man/{coord_trans.rd → coord_trans.Rd}
  122. +18 −0 man/cut_interval.Rd
  123. +16 −0 man/cut_number.Rd
  124. +0 −4 man/cweave.grobGrid.Rd
  125. 0 man/{diamonds.rd → diamonds.Rd}
  126. +0 −4 man/dim.grobGrid.Rd
  127. +0 −6 man/discrete_scale.Rd
  128. 0 man/{economics.rd → economics.Rd}
  129. +27 −0 man/expand_limits.Rd
  130. +18 −0 man/facet.Rd
  131. +3 −0 man/{facet_grid.rd → facet_grid.Rd}
  132. +12 −0 man/facet_null.Rd
  133. +4 −8 man/{facet_wrap.rd → facet_wrap.Rd}
  134. +7 −4 man/fortify.lm.Rd
  135. +4 −2 man/fortify.map.Rd
  136. +2 −1 man/{geom_abline.rd → geom_abline.Rd}
  137. +3 −4 man/{geom_bar.rd → geom_bar.Rd}
  138. +8 −0 man/geom_bin2d.Rd
  139. 0 man/{geom_blank.rd → geom_blank.Rd}
  140. 0 man/{geom_boxplot.rd → geom_boxplot.Rd}
  141. 0 man/{geom_contour.rd → geom_contour.Rd}
  142. 0 man/{geom_crossbar.rd → geom_crossbar.Rd}
  143. 0 man/{geom_density2d.rd → geom_density2d.Rd}
  144. +1 −1 man/{geom_errorbar.rd → geom_errorbar.Rd}
  145. 0 man/{geom_errorbarh.rd → geom_errorbarh.Rd}
  146. 0 man/{geom_freqpoly.rd → geom_freqpoly.Rd}
  147. 0 man/{geom_hex.rd → geom_hex.Rd}
  148. 0 man/{geom_histogram.rd → geom_histogram.Rd}
  149. 0 man/{geom_hline.rd → geom_hline.Rd}
  150. +3 −2 man/{geom_line.rd → geom_line.Rd}
  151. 0 man/{geom_linerange.rd → geom_linerange.Rd}
  152. +10 −9 man/{geom_path.rd → geom_path.Rd}
  153. 0 man/{geom_point.rd → geom_point.Rd}
  154. +6 −3 man/geom_segment.Rd
  155. 0 man/{geom_step.rd → geom_step.Rd}
  156. +8 −2 man/geom_text.Rd
  157. +1 −1 man/geom_tile.Rd
  158. +1 −1 man/ggplot-add.Rd
  159. +0 −4 man/grid.draw.grobGrid.Rd
  160. +0 −4 man/interleave.unit.Rd
  161. +9 −0 man/is.coord.Rd
  162. +12 −0 man/is.facet.Rd
  163. +2 −2 man/label_both.Rd
  164. +2 −2 man/label_bquote.Rd
  165. +2 −2 man/label_value.Rd
  166. +18 −0 man/limits.Rd
  167. +4 −2 man/map_data.Rd
  168. 0 man/{midwest.rd → midwest.Rd}
  169. 0 man/{movies.rd → movies.Rd}
  170. 0 man/{mpg.rd → mpg.Rd}
  171. 0 man/{msleep.rd → msleep.Rd}
  172. +19 −0 man/muted.Rd
  173. +2 −1 man/position_fill.Rd
  174. 0 man/{presidential.rd → presidential.Rd}
  175. +0 −4 man/print.grobGrid.Rd
  176. +0 −4 man/print.proto.Rd
  177. +0 −9 man/print.theme.Rd
  178. +3 −3 man/qplot.Rd
  179. +0 −4 man/rbind.grobGrid.Rd
  180. +0 −4 man/rweave.grobGrid.Rd
  181. +1 −1 man/scale_alpha_continuous.Rd
  182. +0 −4 man/scale_breaks.Rd
  183. +0 −4 man/scale_clone.position_c.Rd
  184. +8 −1 man/scale_colour_gradient.Rd
  185. +5 −1 man/scale_colour_gradient2.Rd
  186. +11 −7 man/scale_colour_gradientn.Rd
  187. +11 −2 man/scale_colour_grey.Rd
  188. +11 −2 man/scale_colour_hue.Rd
  189. +13 −5 man/scale_continuous.Rd
  190. +0 −4 man/scale_dimension.Rd
  191. +0 −4 man/scale_dimension.position_d.Rd
  192. +0 −4 man/scale_labels.Rd
  193. +3 −3 man/{scale_linetype_discrete.Rd → scale_linetype.Rd}
  194. +0 −4 man/scale_map.Rd
  195. +0 −4 man/scale_map.position_c.Rd
  196. +0 −4 man/scale_map.position_d.Rd
  197. +3 −3 man/scale_size_continuous.Rd
  198. +0 −4 man/scale_train.position_d.Rd
  199. +0 −4 man/scale_transform.Rd
  200. +2 −2 man/scale_x_date.Rd
  201. +2 −2 man/scale_x_discrete.Rd
  202. 0 man/{seals.rd → seals.Rd}
  203. +14 −0 man/should_stop.Rd
  204. +3 −3 man/stat_boxplot.Rd
  205. +2 −2 man/stat_contour.Rd
  206. +1 −1 man/stat_density.Rd
  207. +2 −2 man/stat_sum.Rd
  208. +1 −1 man/stat_summary.Rd
  209. +17 −0 man/xlim.Rd
  210. +16 −0 man/ylim.Rd
  211. +35 −0 test/test-data.r
View
217 DESCRIPTION
@@ -13,61 +13,172 @@ Description: An implementation of the grammar of graphics
conditioning system and a consistent interface to map
data to aesthetic attributes. See the ggplot2 website
for more information, documentation and examples.
-Depends: reshape (>= 0.8.0), proto
-Imports: plyr (>= 1.0), digest, grid, scales
-Suggests: quantreg, Hmisc, mapproj, maps, hexbin, gpclib,
+Depends:
+ proto
+Imports:
+ plyr (>= 1.0),
+ digest,
+ grid,
+ reshape2,
+ scales
+Suggests:
+ quantreg,
+ Hmisc,
+ mapproj,
+ maps,
+ hexbin,
+ gpclib,
maptools
-Extends: sp
+Extends:
+ sp
License: GPL-2
URL: http://had.co.nz/ggplot2/
LazyLoad: false
LazyData: true
-Collate: 'aaa-.r' 'aaa-constants.r' 'aaa-html.r' 'aes.r'
- 'annotation.r' 'coord-.r' 'coord-cartesian-.r'
- 'coord-cartesian-equal.r' 'coord-cartesian-flipped.r'
- 'coord-map.r' 'coord-munch.r' 'coord-polar.r'
- 'coord-transform.r' 'facet-.r' 'facet-grid-.r'
- 'facet-labels.r' 'facet-viewports.r' 'facet-wrap.r'
- 'fortify-lm.r' 'fortify-map.r' 'fortify-spatial.r'
- 'fortify.r' 'geom-.r' 'geom-abline.r' 'geom-bar-.r'
- 'geom-bar-histogram.r' 'geom-bin2d.r' 'geom-blank.r'
- 'geom-boxplot.r' 'geom-crossbar.r' 'geom-defaults.r'
- 'geom-error.r' 'geom-errorh.r' 'geom-freqpoly.r'
- 'geom-hex.r' 'geom-hline.r' 'geom-linerange.r'
- 'geom-path-.r' 'geom-path-contour.r'
- 'geom-path-density2d.r' 'geom-path-line.r'
- 'geom-path-step.r' 'geom-point-.r'
- 'geom-point-jitter.r' 'geom-pointrange.r'
- 'geom-polygon.r' 'geom-quantile.r' 'geom-rect.r'
- 'geom-ribbon-.r' 'geom-ribbon-density.r' 'geom-rug.r'
- 'geom-segment.r' 'geom-smooth.r' 'geom-text.r'
- 'geom-tile.r' 'geom-vline.r' 'ggplot2.r'
- 'grob-absolute.r' 'grob-grid.r' 'grob-null.r'
- 'guides-axis.r' 'guides-grid.r'
- 'labels.r' 'layer.r' 'limits.r' 'matrix.r'
- 'plot-build.r' 'plot-construction.r' 'plot-last.r'
- 'plot-render.r' 'plot.r' 'position-.r'
- 'position-collide.r' 'position-dodge.r'
- 'position-fill.r' 'position-identity.r'
- 'position-jitter.r' 'position-stack.r' 'quick-plot.r'
- 'save.r' 'scale-.r' 'scale-alpha.r' 'scale-area.r'
- 'scale-brewer.r' 'scale-continuous.r' 'scale-date.r'
- 'scale-datetime.r' 'scale-discrete-.r'
- 'scale-gradient.r' 'scale-gradient2.r'
- 'scale-gradientn.r' 'scale-grey.r' 'scale-hue.r'
- 'scale-identity.r' 'scale-linetype.r' 'scale-manual.r'
- 'scale-shape.r' 'scale-size.r' 'scales-.r' 'stat-.r'
- 'stat-bin.r' 'stat-bin2d.r' 'stat-binhex.r'
- 'stat-boxplot.r' 'stat-contour.r' 'stat-density-2d.r'
- 'stat-density.r' 'stat-function.r' 'stat-identity.r'
- 'stat-qq.r' 'stat-quantile.r' 'stat-smooth-methods.r'
- 'stat-smooth.r' 'stat-spoke.r' 'stat-sum.r'
- 'stat-summary.r' 'stat-unique.r' 'stat-vline.r'
- 'summary.r' 'templates.r' 'theme-defaults.r'
- 'theme-elements.r' 'theme.r' 'utilities-break.r'
- 'utilities-colour.r' 'utilities-discrete.r'
- 'utilities-facet.r' 'utilities-grid.r'
- 'utilities-layer.r' 'utilities-matrix.r'
- 'utilities-position.r' 'utilities-resolution.r'
- 'utilities.r' 'xxx-codegen.r' 'xxx-digest.r' 'xxx.r'
- 'zxx.r' 'guides-.r' 'guide-legend.r' 'guide-colorbar.r'
+Collate:
+ 'aaa-.r'
+ 'aaa-constants.r'
+ 'aaa-html.r'
+ 'aes.r'
+ 'annotation.r'
+ 'bench.r'
+ 'coord-.r'
+ 'coord-cartesian-.r'
+ 'coord-fixed.r'
+ 'coord-flip.r'
+ 'coord-map.r'
+ 'coord-munch.r'
+ 'coord-polar.r'
+ 'coord-transform.r'
+ 'facet-.r'
+ 'facet-grid-.r'
+ 'facet-labels.r'
+ 'facet-layout.r'
+ 'facet-locate.r'
+ 'facet-null.r'
+ 'facet-viewports.r'
+ 'facet-wrap.r'
+ 'fortify-lm.r'
+ 'fortify-map.r'
+ 'fortify-spatial.r'
+ 'fortify.r'
+ 'geom-.r'
+ 'geom-abline.r'
+ 'geom-bar-.r'
+ 'geom-bar-histogram.r'
+ 'geom-bin2d.r'
+ 'geom-blank.r'
+ 'geom-boxplot.r'
+ 'geom-crossbar.r'
+ 'geom-defaults.r'
+ 'geom-error.r'
+ 'geom-errorh.r'
+ 'geom-freqpoly.r'
+ 'geom-hex.r'
+ 'geom-hline.r'
+ 'geom-linerange.r'
+ 'geom-path-.r'
+ 'geom-path-contour.r'
+ 'geom-path-density2d.r'
+ 'geom-path-line.r'
+ 'geom-path-step.r'
+ 'geom-point-.r'
+ 'geom-point-jitter.r'
+ 'geom-pointrange.r'
+ 'geom-polygon.r'
+ 'geom-quantile.r'
+ 'geom-rect.r'
+ 'geom-ribbon-.r'
+ 'geom-ribbon-density.r'
+ 'geom-rug.r'
+ 'geom-segment.r'
+ 'geom-smooth.r'
+ 'geom-text.r'
+ 'geom-tile.r'
+ 'geom-vline.r'
+ 'ggplot2.r'
+ 'grob-absolute.r'
+ 'grob-null.r'
+ 'guides-axis.r'
+ 'guides-grid.r'
+ 'labels.r'
+ 'layer.r'
+ 'limits.r'
+ 'matrix.r'
+ 'panel.r'
+ 'plot-build.r'
+ 'plot-construction.r'
+ 'plot-last.r'
+ 'plot-render.r'
+ 'plot.r'
+ 'position-.r'
+ 'position-collide.r'
+ 'position-dodge.r'
+ 'position-fill.r'
+ 'position-identity.r'
+ 'position-jitter.r'
+ 'position-stack.r'
+ 'quick-plot.r'
+ 'save.r'
+ 'scale-.r'
+ 'scale-alpha.r'
+ 'scale-area.r'
+ 'scale-brewer.r'
+ 'scale-continuous.r'
+ 'scale-date.r'
+ 'scale-datetime.r'
+ 'scale-discrete-.r'
+ 'scale-gradient.r'
+ 'scale-gradient2.r'
+ 'scale-gradientn.r'
+ 'scale-grey.r'
+ 'scale-hue.r'
+ 'scale-identity.r'
+ 'scale-linetype.r'
+ 'scale-manual.r'
+ 'scale-shape.r'
+ 'scale-size.r'
+ 'scales-.r'
+ 'stat-.r'
+ 'stat-bin.r'
+ 'stat-bin2d.r'
+ 'stat-binhex.r'
+ 'stat-boxplot.r'
+ 'stat-contour.r'
+ 'stat-density-2d.r'
+ 'stat-density.r'
+ 'stat-function.r'
+ 'stat-identity.r'
+ 'stat-qq.r'
+ 'stat-quantile.r'
+ 'stat-smooth-methods.r'
+ 'stat-smooth.r'
+ 'stat-spoke.r'
+ 'stat-sum.r'
+ 'stat-summary.r'
+ 'stat-unique.r'
+ 'stat-vline.r'
+ 'summary.r'
+ 'templates.r'
+ 'theme-defaults.r'
+ 'theme-elements.r'
+ 'theme.r'
+ 'utilities-break.r'
+ 'utilities-colour.r'
+ 'utilities-discrete.r'
+ 'utilities-facet.r'
+ 'utilities-grid.r'
+ 'utilities-layer.r'
+ 'utilities-matrix.r'
+ 'utilities-position.r'
+ 'utilities-resolution.r'
+ 'utilities-table-template.r'
+ 'utilities-table.r'
+ 'utilities.r'
+ 'xxx-codegen.r'
+ 'xxx-digest.r'
+ 'xxx.r'
+ 'zxx.r'
+ 'guides-.r'
+ 'guide-legend.r'
+ 'guide-colorbar.r'
View
116 NAMESPACE
@@ -7,20 +7,66 @@ export(aes)
export(aes_string)
export(aes_all)
export(annotate)
+export(benchplot)
+export(coord)
+export(is.coord)
+S3method(coord_render_bg, default)
+S3method(coord_render_axis_h, default)
+S3method(coord_render_axis_v, default)
export(coord_cartesian)
+S3method(is.linear, cartesian)
+S3method(coord_distance, cartesian)
+S3method(coord_transform, cartesian)
+S3method(coord_train, cartesian)
export(coord_fixed, coord_equal)
+S3method(coord_aspect, fixed)
export(coord_flip)
+S3method(is.linear, flip)
+S3method(coord_transform, flip)
+S3method(coord_train, flip)
+S3method(coord_labels, flip)
export(coord_map)
+S3method(coord_transform, map)
+S3method(coord_distance, map)
+S3method(coord_aspect, map)
+S3method(coord_train, map)
+S3method(coord_render_bg, map)
+S3method(coord_render_axis_h, map)
+S3method(coord_render_axis_v, map)
export(coord_polar)
+S3method(coord_aspect, polar)
+S3method(coord_distance, polar)
+S3method(coord_train, polar)
+S3method(coord_transform, polar)
+S3method(coord_render_axis_v, polar)
+S3method(coord_render_axis_h, polar)
+S3method(coord_render_bg, polar)
+S3method(coord_render_fg, polar)
export(coord_trans)
+S3method(coord_distance, trans)
+S3method(coord_transform, trans)
+S3method(coord_train, trans)
+export(facet)
+export(is.facet)
export(facet_grid)
+S3method(facet_train_layout, grid)
+S3method(facet_map_layout, grid)
+S3method(facet_render, grid)
export(label_value)
export(label_both)
export(label_parsed)
export(label_bquote)
+export(facet_null)
+S3method(facet_train_layout, null)
+S3method(facet_map_layout, null)
+S3method(facet_render, null)
export(facet_wrap)
+S3method(facet_train_layout, wrap)
+S3method(facet_map_layout, wrap)
+S3method(facet_render, wrap)
S3method(fortify, lm)
S3method(fortify, map)
+export(map_data)
S3method(fortify, SpatialPolygons)
S3method(fortify, Polygons)
S3method(fortify, Polygon)
@@ -34,6 +80,7 @@ export(fortify)
export(geom_abline)
export(geom_bar)
export(geom_histogram)
+export(geom_bin2d)
export(geom_blank)
export(geom_boxplot)
export(geom_crossbar)
@@ -43,6 +90,7 @@ export(geom_freqpoly)
export(geom_hex)
export(geom_hline)
export(geom_linerange)
+export(geom_path)
export(geom_contour)
export(geom_density2d)
export(geom_line)
@@ -62,27 +110,28 @@ export(geom_smooth)
export(geom_text)
export(geom_tile)
export(geom_vline)
-import(plyr, digest, scales, grid)
+import(plyr, digest, scales, grid, reshape2)
S3method(grobHeight, absoluteGrob)
S3method(grobWidth, absoluteGrob)
S3method(grobX, absoluteGrob)
S3method(grobY, absoluteGrob)
S3method(grid.draw, absoluteGrob)
-S3method(print, grobGrid)
-S3method(dim, grobGrid)
-S3method(rbind, grobGrid)
-S3method(as.list, unit)
-S3method(interleave, unit)
-S3method(rweave, grobGrid)
-S3method(cbind, grobGrid)
-S3method(cweave, grobGrid)
-S3method(grid.draw, grobGrid)
S3method(widthDetails, zeroGrob)
S3method(heightDetails, zeroGrob)
S3method(grobWidth, zeroGrob)
S3method(grobHeight, zeroGrob)
S3method(drawDetails, zeroGrob)
+export(update_labels)
export(labs, xlab, ylab)
+export(xlim)
+export(ylim)
+S3method(limits, numeric)
+S3method(limits, character)
+S3method(limits, factor)
+S3method(limits, Date)
+S3method(limits, POSIXct)
+S3method(limits, POSIXlt)
+export(expand_limits)
export(plotmatrix)
S3method("+", ggplot)
export("%+%")
@@ -102,6 +151,7 @@ export(continuous_scale)
export(discrete_scale)
S3method(scale_train, continuous)
S3method(scale_train, discrete)
+S3method(scale_reset, default)
S3method(scale_transform, continuous)
S3method(scale_transform, discrete)
S3method(scale_map, continuous)
@@ -112,21 +162,32 @@ S3method(scale_breaks, continuous)
S3method(scale_breaks, discrete)
S3method(scale_labels, continuous)
S3method(scale_labels, discrete)
-export(scale_alpha_continuous)
+S3method(scale_clone, continuous)
+export(scale_alpha, scale_alpha_continuous)
+export(scale_alpha_discrete)
export(scale_area)
-export(scale_colour_brewer)
-export(scale_x_continuous, scale_y_continuous)
+export(scale_colour_brewer, scale_fill_brewer)
+export(scale_x_continuous, scale_y_continuous, scale_x_log10, scale_y_log10, scale_x_reverse, scale_y_reverse, scale_x_sqrt, scale_y_sqrt)
S3method(scale_map, position_c)
-S3method(scale_clone, position_c)
-export(scale_x_date)
-export(scale_x_datetime)
+export(scale_x_date, scale_y_date)
+export(scale_x_datetime, scale_y_datetime)
+export(scale_x_discrete, scale_y_discrete)
S3method(scale_train, position_d)
+S3method(scale_limits, position_d)
+S3method(scale_reset, position_d)
S3method(scale_map, position_d)
S3method(scale_dimension, position_d)
-export(scale_colour_gradient)
-export(scale_linetype_discrete)
-export(scale_shape)
-export(scale_size_continuous)
+export(scale_colour_gradient, scale_fill_gradient)
+export(scale_colour_gradient2, scale_fill_gradient2)
+export(scale_colour_gradientn, scale_fill_gradientn)
+export(scale_colour_grey, scale_fill_grey)
+export(scale_colour_hue, scale_fill_hue)
+export(scale_colour_identity, scale_fill_identity, scale_shape_identity, scale_linetype_identity, scale_alpha_identity, scale_size_identity)
+S3method(scale_map, identity)
+export(scale_linetype, scale_linetype_continuous, scale_linetype_discrete)
+export(scale_colour_manual, scale_fill_manual, scale_shape_manual, scale_linetype_manual, scale_alpha_manual, scale_size_manual)
+export(scale_shape, scale_shape_discrete, scale_shape_continuous)
+export(scale_size, scale_size_continuous)
export(scale_size_discrete)
export(stat_bin)
export(stat_bin2d)
@@ -150,6 +211,7 @@ export(stat_abline)
export(stat_vline)
export(stat_hline)
S3method(summary, ggplot)
+export(ggpcp)
export(ggfluctuation)
export(ggmissing)
export(ggstructure)
@@ -161,16 +223,24 @@ export(theme_rect)
export(theme_line)
export(theme_segment)
export(theme_text)
-export(theme_update)
+export(theme_update, theme_set, theme_get)
export(opts)
S3method(print, theme)
+export(cut_interval)
+export(cut_number)
+export(muted)
S3method(rweave, list)
S3method(rweave, matrix)
S3method(cweave, list)
S3method(cweave, matrix)
S3method(interleave, list)
+S3method(interleave, unit)
S3method(interleave, default)
-
+S3method(print, gtable)
+S3method(dim, gtable)
+S3method(rbind, gtable)
+S3method(cbind, gtable)
+export(should_stop)
+export(scale_colour_discrete, scale_colour_continuous, scale_fill_discrete, scale_fill_continuous, scale_color_brewer, scale_color_continuous, scale_color_discrete, scale_color_gradient, scale_color_grey, scale_color_hue, scale_color_identity, scale_color_manual, coord_equal)
export(guide_legend)
export(guide_colorbar)
-
View
51 NEWS
@@ -1,5 +1,9 @@
ggplot2 0.9.0 ----------------------------------------------------------------
+* `geom_text` now supports `fontfamily`, `fontface`, and `lineheight`
+ aesthetics for finer control over text display. (Thanks to Kohske Takahashi
+ for the patch. Fixes #60)
+
* `collide`, which powers `position_dodge` and `position_stack`, now does not
error on single x values (Thanks to Brian Diggs for a fix. #157)
@@ -11,8 +15,21 @@ ggplot2 0.9.0 ----------------------------------------------------------------
median line is now `fatten` times the width of the other lines (thanks to
suggestion by Di Cook), and the line type can now be set.
+* Scales now automatically shrink to what is actually displayed on the plot,
+ not the underlying data used for statistical transformation. If you want the
+ old behaviour, supply `shrink = FALSE` to the facetting specification.
+ (Fixes #125)
+
+* When printing a ggplot2 object, the rendered plot information is returned
+ invisibly. You can capture this with (e.g.) `x <- print(qplot(mpg, wt, data
+ = mtcars))` and in the future will be able to use it to get information
+ about the plot computations, such as the range of all the scales, and the
+ exact data that is plotted.
+
+* `scale_shape` finally returns an error when you try and use it with a
+ continuous variable
-DOCUMENTATION
+DEVELOPMENT
* ggplot2 has moved away from the two (!!) homegrown documentation systems
that it previously relied on, and now uses roxygen extensively. The current
@@ -21,7 +38,14 @@ DOCUMENTATION
* ggplot2 now uses a `NAMESPACE`, and only exports functions that should be
user visible - this should make it play considerably more nicely with other
- packages in the R ecosystem
+ packages in the R ecosystem. Note that this means you now need to explicitly
+ load `plyr` (and other packages) if you are using them elsewhere in your
+ code.
+
+* ggplot2 now has a start on a set of automated tests. As this test suite
+ expands it will help me ensure that bugs stay fixed, and that old bugs don't
+ come back in new versions. A test suite also gives me more confidence when
+ I'm modifying code, which should help with general code quality.
SCALES
@@ -46,7 +70,8 @@ SCALES
breaks.
* all scales now accept `na.value` parameter which provides an aesthetic value
- to be used for NA values in the data
+ to be used for NA values in the data. Colour/fill scales default to values
+ that should stand out as being different from non-missing values.
* the new `oob` (out of bounds) parameter controls how scales deals with
values outside the limits. The default action is `censor` - see `clip` for
@@ -66,6 +91,26 @@ SCALES
scale_colour_discrete <- scale_colour_brewer
p
+FACETS
+
+* Converted from proto to S3 objects, and class methods (somewhat) documented
+ in `facet.r`. This should make it easier to develop new types of facetting
+ specifications.
+
+* New `facet_null` used when for no facetting. This special case is
+ implemented more efficiently and results in substantial performance
+ improvements for un-facetted plots.
+
+* Facetting variables will no longer interfere with aesthetic mappings -
+ `facet_wrap(~ colour)` will no longer affect the colour of points.
+
+COORDS
+
+* Converted from proto to S3 objects, and class methods (somewhat) documented
+ in `coord.r`. This should make it easier to develop new types of coordinate
+ systems.
+
+
ggplot2 0.8.9 (2010-12-24) ---------------------------------------------------
A big thanks to Koshke Takahashi, who supplied the majority of improvements in this release!
View
2 R/aes.r
@@ -126,7 +126,7 @@ aes_all <- function(vars) {
# @param params. user specified values
# @value a data.frame, with all factors converted to character strings
aesdefaults <- function(data, y., params.) {
- updated <- updatelist(y., params.)
+ updated <- modifyList(y., params. %||% list())
cols <- tryapply(defaults(data, updated), function(x) eval(x, data, globalenv()))
View
24 R/bench.r
@@ -0,0 +1,24 @@
+#' Benchmark plot creation time.
+#' Broken down into construct, build, render and draw times.
+#'
+#' @param x code to create ggplot2 plot
+#' @export
+#' @keywords internal
+#' @examples
+#' benchplot(qplot(mpg, wt, data = mtcars))
+#' benchplot(qplot(mpg, wt, data = mtcars) + facet_grid(.~ cyl))
+benchplot <- function(x) {
+
+ construct <- system.time(force(x))
+ stopifnot(inherits(x, "ggplot"))
+
+ build <- system.time(data <- ggplot_build(x))
+ render <- system.time(grob <- ggplotGrob(x, data))
+ draw <- system.time(grid.draw(grob))
+
+ times <- rbind(construct, build, render, draw)[, 1:3]
+
+ unrowname(data.frame(
+ step = c("construct", "build", "render", "draw", "TOTAL"),
+ rbind(times, colSums(times))))
+}
View
135 R/coord-.r
@@ -1,64 +1,71 @@
-Coord <- proto(TopLevel, expr={
- limits <- list()
- class <- function(.) "coord"
-
- muncher <- function(.) FALSE
-
- # Rescaling at coord level should not be clipped: this is what
- # makes zooming work
- rescale_var <- function(., data, range, clip = FALSE) {
- rescale(data, 0:1, range)
- }
-
- munch <- function(., data, details, segment_length = 0.01) {
- if (!.$muncher()) return(.$transform(data, details))
-
- # Calculate distances using coord distance metric
- dist <- .$distance(data$x, data$y, details)
- dist[data$group[-1] != data$group[-nrow(data)]] <- NA
-
- # Munch and then transform result
- munched <- munch_data(data, dist, segment_length)
- .$transform(munched, details)
- }
-
- distance <- function(., x, y, details) {
- max_dist <- dist_euclidean(details$x.range, details$y.range)
- dist_euclidean(x, y) / max_dist
- }
-
- compute_aspect <- function(., ranges) {
- NULL
- }
-
- labels <- function(., scales) {
- scales
- }
-
- pprint <- function(., newline=TRUE) {
- args <- formals(get("new", .))
- args <- args[!names(args) %in% c(".", "...")]
-
- cat("coord_", .$objname, ": ", clist(args), sep="")
-
- if (newline) cat("\n")
- }
-
- guide_foreground <- function(., scales, theme) {
- theme_render(theme, "panel.border")
- }
- # Html defaults
-
- html_returns <- function(.) {
- ps(
- "<h2>Returns</h2>\n",
- "<p>This function returns a coordinate system object.</p>"
- )
- }
-
- parameters <- function(.) {
- params <- formals(get("new", .))
- params[setdiff(names(params), c("."))]
- }
-
-})
+#' New coordinate system.
+#'
+#' Internal use only.
+#'
+#' @param ... object fields
+#' @keywords internal
+#' @export
+coord <- function(..., subclass = c()) {
+ structure(list(...), class = c(subclass, "coord"))
+}
+
+#' Is this object a coordinate system?
+#'
+#' @export is.coord
+#' @keywords internal
+is.coord <- function(x) inherits(x, "coord")
+
+distance <- function(., x, y, details) {
+ max_dist <- dist_euclidean(details$x.range, details$y.range)
+ dist_euclidean(x, y) / max_dist
+}
+
+coord_aspect <- function(coord, ranges)
+ UseMethod("coord_aspect")
+coord_aspect.default <- function(coord, ranges) NULL
+
+coord_labels <- function(coord, scales) UseMethod("coord_labels")
+coord_labels.default <- function(coord, scales) scales
+
+coord_render_fg <- function(coord, scales, theme)
+ UseMethod("coord_render_fg")
+coord_render_fg.default <- function(coord, scales, theme)
+ theme_render(theme, "panel.border")
+
+coord_render_bg <- function(coord, scales, theme)
+ UseMethod("coord_render_bg")
+#' @S3method coord_render_bg default
+coord_render_bg.default <- function(coord, details, theme) {
+ x.major <- unit(details$x.major, "native")
+ x.minor <- unit(details$x.minor, "native")
+ y.major <- unit(details$y.major, "native")
+ y.minor <- unit(details$y.minor, "native")
+
+ guide_grid(theme, x.minor, x.major, y.minor, y.major)
+}
+
+coord_render_axis_h <- function(coord, scales, theme)
+ UseMethod("coord_render_axis_h")
+#' @S3method coord_render_axis_h default
+coord_render_axis_h.default <- function(coord, details, theme) {
+ guide_axis(details$x.major, details$x.labels, "bottom", theme)
+}
+
+coord_render_axis_v <- function(coord, scales, theme)
+ UseMethod("coord_render_axis_v")
+#' @S3method coord_render_axis_v default
+coord_render_axis_v.default <- function(coord, details, theme) {
+ guide_axis(details$y.major, details$y.labels, "left", theme)
+}
+
+coord_train <- function(coord, scales)
+ UseMethod("coord_train")
+
+coord_transform <- function(coord, data, range)
+ UseMethod("coord_transform")
+
+coord_distance <- function(coord, x, y, details)
+ UseMethod("coord_distance")
+
+is.linear <- function(coord) UseMethod("is.linear")
+is.linear.default <- function(coord) FALSE
View
130 R/coord-cartesian-.r
@@ -5,7 +5,6 @@
#' plot (like you're looking at it with a magnifying class), and will not
#' change the underlying data like setting limits on a scale will.
#'
-#' @name coord_cartesian
#' @param xlim limits for the x axis
#' @param ylim limits for the y axis
#' @param wise If \code{TRUE} will wisely expand the actual range of the plot
@@ -39,81 +38,72 @@
#' # When zooming the coordinate system, we see a subset of original 50 bins,
#' # displayed bigger
#' d + coord_cartesian(xlim = c(0, 2))
-CoordCartesian <- proto(Coord, expr={
- objname <- "cartesian"
- new <- function(., xlim = NULL, ylim = NULL, wise = FALSE) {
- .$proto(limits = list(x = xlim, y = ylim), wise = wise)
- }
-
- transform <- function(., data, details) {
- rescale_x <- function(data) .$rescale_var(data, details$x.range)
- rescale_y <- function(data) .$rescale_var(data, details$y.range)
-
- data <- transform_position(data, rescale_x, rescale_y)
- transform_position(data, trim_infinite_01, trim_infinite_01)
- }
+coord_cartesian <- function(xlim = NULL, ylim = NULL, wise = FALSE) {
+ coord(limits = list(x = xlim, y = ylim), wise = wise,
+ subclass = "cartesian")
+}
+
+#' @S3method is.linear cartesian
+is.linear.cartesian <- function(coord) TRUE
+
+#' @S3method coord_distance cartesian
+coord_distance.cartesian <- function(coord, x, y, details) {
+ max_dist <- dist_euclidean(details$x.range, details$y.range)
+ dist_euclidean(x, y) / max_dist
+}
+
+#' @S3method coord_transform cartesian
+coord_transform.cartesian <- function(., data, details) {
+ rescale_x <- function(data) rescale(data, from = details$x.range)
+ rescale_y <- function(data) rescale(data, from = details$y.range)
- compute_ranges <- function(., scales) {
- if (is.null(.$limits$x)) {
- x.range <- scale_dimension(scales$x)
- } else {
- if (.$wise) {
- x.range <- expand_range(range(scales$x$.tr$transform(.$limits[["x"]])), scales$x$.expand[1], scales$x$.expand[2])
- scales$x$.domain <- .$limits[["x"]]
- } else {
- x.range <- range(scales$x$.tr$transform(.$limits[["x"]]))
- }
- }
-
- x.major <- .$rescale_var(scale_break_positions(scales$x), x.range, TRUE)
- x.minor <- .$rescale_var(scale_breaks_minor(scales$x), x.range, TRUE)
- x.labels <- scale_labels(scales$x)
+ data <- transform_position(data, rescale_x, rescale_y)
+ transform_position(data, trim_infinite_01, trim_infinite_01)
+}
- if (is.null(.$limits$y)) {
- y.range <- scale_dimension(scales$y)
- } else {
- if (.$wise) {
- y.range <- expand_range(range(scales$y$.tr$transform(.$limits[["y"]])), scales$y$.expand[1], scales$y$.expand[2])
- scales$y$.domain<-.$limits[["y"]]
- } else {
- y.range <- range(scales$y$.tr$transform(.$limits[["y"]]))
- }
+#' @S3method coord_train cartesian
+coord_train.cartesian <- function(coord, scales) {
+ if (is.null(coord$limits$x)) {
+ x.range <- scale_dimension(scales$x)
+ } else {
+ x.range <- range(scale_transform(scales$x, coord$limits[["x"]]))
+ if (coord$wise) {
+ scales$x$limits <- x.range
+ x.range <- expand_range(x.range,
+ scales$x$expand[1], scales$x$expand[2])
}
- y.major <- .$rescale_var(scale_breaks(scales$y), y.range, TRUE)
- y.minor <- .$rescale_var(scale_breaks_minor(scales$y), y.range, TRUE)
- y.labels <- scale_labels(scales$y)
-
- list(
- x.range = x.range, y.range = y.range,
- x.major = x.major, x.minor = x.minor, x.labels = x.labels,
- y.major = y.major, y.minor = y.minor, y.labels = y.labels
- )
}
- guide_axis_h <- function(., details, theme) {
- guide_axis(details$x.major, details$x.labels, "bottom", theme)
- }
+ x.major <- rescale(scale_break_positions(scales$x), from = x.range)
+ x.minor <- rescale(scale_breaks_minor(scales$x), from = x.range)
+ x.labels <- scale_labels(scales$x)
- guide_axis_v <- function(., details, theme) {
- guide_axis(details$y.major, details$y.labels, "left", theme)
- }
-
-
- guide_background <- function(., details, theme) {
- x.major <- unit(details$x.major, "native")
- x.minor <- unit(details$x.minor, "native")
- y.major <- unit(details$y.major, "native")
- y.minor <- unit(details$y.minor, "native")
+ if (is.null(coord$limits$y)) {
+ y.range <- scale_dimension(scales$y)
+ } else {
+ y.range <- range(scale_transform(scales$y, coord$limits$y))
- guide_grid(theme, x.minor, x.major, y.minor, y.major)
- }
-
- icon <- function(.) {
- gTree(children = gList(
- segmentsGrob(c(0, 0.25), c(0.25, 0), c(1, 0.25), c(0.25, 1), gp=gpar(col="grey50", lwd=0.5)),
- segmentsGrob(c(0, 0.75), c(0.75, 0), c(1, 0.75), c(0.75, 1), gp=gpar(col="grey50", lwd=0.5)),
- segmentsGrob(c(0, 0.5), c(0.5, 0), c(1, 0.5), c(0.5, 1))
- ))
+ if (coord$wise) {
+ scales$y$limits <- y.range
+ y.range <- expand_range(y.range,
+ scales$y$expand[1], scales$y$expand[2])
+ }
}
+ y.major <- rescale(scale_break_positions(scales$y), from = y.range)
+ y.minor <- rescale(scale_breaks_minor(scales$y), from = y.range)
+ y.labels <- scale_labels(scales$y)
-})
+ list(
+ x.range = x.range, y.range = y.range,
+ x.major = x.major, x.minor = x.minor, x.labels = x.labels,
+ y.major = y.major, y.minor = y.minor, y.labels = y.labels
+ )
+}
+
+icon.cartesian <- function(.) {
+ gTree(children = gList(
+ segmentsGrob(c(0, 0.25), c(0.25, 0), c(1, 0.25), c(0.25, 1), gp=gpar(col="grey50", lwd=0.5)),
+ segmentsGrob(c(0, 0.75), c(0.75, 0), c(1, 0.75), c(0.75, 1), gp=gpar(col="grey50", lwd=0.5)),
+ segmentsGrob(c(0, 0.5), c(0.5, 0), c(1, 0.5), c(0.5, 1))
+ ))
+}
View
69 R/coord-cartesian-flipped.r
@@ -1,69 +0,0 @@
-#' Flipped cartesian coordinates.
-#'
-#' Flipped cartesian coordinates so that horizontal becomes vertical, and
-#' vertical, horizontal. This is primarily useful for converting geoms and
-#' statistics which display y conditional on x, to x conditional on y.
-#'
-#' @name coord_flip
-#' @export
-#' @examples
-#' # Very useful for creating boxplots, and other interval
-#' # geoms in the horizontal instead of vertical position.
-#' qplot(cut, price, data=diamonds, geom="boxplot")
-#' last_plot() + coord_flip()
-#'
-#' qplot(cut, data=diamonds, geom="bar")
-#' last_plot() + coord_flip()
-#'
-#' qplot(carat, data=diamonds, geom="histogram")
-#' last_plot() + coord_flip()
-#'
-#' # You can also use it to flip lines and area plots:
-#' qplot(1:5, (1:5)^2, geom="line")
-#' last_plot() + coord_flip()
-CoordFlip <- proto(CoordCartesian, expr={
- objname <- "flip"
-
-
- transform <- function(., data, details) {
- rescale_x <- function(data) .$rescale_var(data, details$x.range)
- rescale_y <- function(data) .$rescale_var(data, details$y.range)
-
- data <- transform_position(data, rescale_y, rescale_x)
- data <- transform_position(data, trim_infinite_01, trim_infinite_01)
-
- rename(data, c(
- x = "y", y = "x",
- xend = "yend", yend = "xend",
- xmin = "ymin", ymin = "xmin",
- xmax = "ymax", ymax = "xmax")
- )
- }
-
- compute_ranges <- function(., scales) {
- details <- .super$compute_ranges(., scales)
- with(details, list(
- x.range = y.range, y.range = x.range,
- x.major = y.major, x.minor = y.minor, x.labels = y.labels,
- y.major = x.major, y.minor = x.minor, y.labels = x.labels
- ))
- }
-
- labels <- function(., scales) {
- list(
- x = scales$y,
- y = scales$x
- )
- }
-
-
- icon <- function(.) {
- angles <- seq(0, pi/2, length=20)[-c(1, 20)]
- gTree(children=gList(
- segmentsGrob(0, 0, 0, 1),
- segmentsGrob(0, 0, 1, 0),
- linesGrob(0.9 * sin(angles), 0.9 * cos(angles), arrow=arrow(length=unit(0.05, "npc"))),
- linesGrob(0.5 * sin(angles), 0.5 * cos(angles), arrow=arrow(end="first", length= unit(0.05, "npc")))
- ))
- }
-})
View
22 R/coord-cartesian-equal.r → R/coord-fixed.r
@@ -8,7 +8,6 @@
#' longer than units on the x-axis, and vice versa. This is similar to
#' \code{\link[MASS]{eqscplot}}, but it works for all types of graphics.
#'
-#' @name coord_fixed
#' @aliases coord_fixed coord_equal
#' @export coord_fixed coord_equal
#' @examples
@@ -20,17 +19,14 @@
#' qplot(mpg, wt, data = mtcars) + coord_equal(ratio = 1/5)
#'
#' # Resize the plot to see that the specified aspect ratio is mantained
-CoordFixed <- proto(CoordCartesian, {
- objname <- "fixed"
+coord_fixed <- function(ratio = 1) {
+ coord(ratio = ratio, subclass = c("fixed", "cartesian"))
+}
+coord_equal <- coord_fixed
- new <- function(., ratio = 1) {
- .$proto(ratio = ratio)
- }
+#' @S3method coord_aspect fixed
+coord_aspect.fixed <- function(coord, ranges) {
+ diff(ranges$y.range) / diff(ranges$x.range) * coord$ratio
+}
- compute_aspect <- function(., ranges) {
- diff(ranges$y.range) / diff(ranges$x.range) * .$ratio
- }
-
- icon <- function(.) textGrob("=", gp = gpar(cex=3))
-
-})
+icon.fixed <- function() textGrob("=", gp = gpar(cex=3))
View
68 R/coord-flip.r
@@ -0,0 +1,68 @@
+#' Flipped cartesian coordinates.
+#'
+#' Flipped cartesian coordinates so that horizontal becomes vertical, and
+#' vertical, horizontal. This is primarily useful for converting geoms and
+#' statistics which display y conditional on x, to x conditional on y.
+#'
+#' @export
+#' @examples
+#' # Very useful for creating boxplots, and other interval
+#' # geoms in the horizontal instead of vertical position.
+#' qplot(cut, price, data=diamonds, geom="boxplot")
+#' last_plot() + coord_flip()
+#'
+#' qplot(cut, data=diamonds, geom="bar")
+#' last_plot() + coord_flip()
+#'
+#' h <- qplot(carat, data=diamonds, geom="histogram")
+#' h
+#' h + coord_flip()
+#' h + coord_flip() + scale_x_reverse()
+#'
+#' # You can also use it to flip lines and area plots:
+#' qplot(1:5, (1:5)^2, geom="area")
+#' last_plot() + coord_flip()
+coord_flip <- function(...) {
+ coord <- coord_cartesian(...)
+ structure(coord, class = c("flip", class(coord)))
+}
+
+flip_labels <- function(x) {
+ old_names <- names(x)
+
+ new_names <- old_names
+ new_names <- gsub("^x", "z", new_names)
+ new_names <- gsub("^y", "x", new_names)
+ new_names <- gsub("^z", "y", new_names)
+
+ setNames(x, new_names)
+}
+
+#' @S3method is.linear flip
+is.linear.flip <- function(coord) FALSE
+
+#' @S3method coord_transform flip
+coord_transform.flip <- function(coord, data, details) {
+ data <- flip_labels(data)
+ NextMethod()
+}
+
+#' @S3method coord_train flip
+coord_train.flip <- function(coord, scales) {
+ flip_labels(NextMethod())
+}
+
+#' @S3method coord_labels flip
+coord_labels.flip <- function(coord, scales) {
+ flip_labels(NextMethod())
+}
+
+icon.flip <- function(.) {
+ angles <- seq(0, pi/2, length=20)[-c(1, 20)]
+ gTree(children=gList(
+ segmentsGrob(0, 0, 0, 1),
+ segmentsGrob(0, 0, 1, 0),
+ linesGrob(0.9 * sin(angles), 0.9 * cos(angles), arrow=arrow(length=unit(0.05, "npc"))),
+ linesGrob(0.5 * sin(angles), 0.5 * cos(angles), arrow=arrow(end="first", length= unit(0.05, "npc")))
+ ))
+}
View
241 R/coord-map.r
@@ -6,7 +6,6 @@
#' This is still experimental, and if you have any advice to offer regarding
#' a better (or more correct) way to do this, please let me know
#'
-#' @name coord_map
#' @export
#' @param projection projection to use, see \code{\link{mapproject}} for
#' list
@@ -18,7 +17,7 @@
#' @param ylim manually specific y limits (in degrees of latitude)
#' @export
#' @examples
-#' try_require("maps")
+#' if (require("maps")) {
#' # Create a lat-long dataframe from the maps package
#' nz <- data.frame(map("nz", plot=FALSE)[c("x","y")])
#' (nzmap <- qplot(x, y, data=nz, geom="path"))
@@ -41,134 +40,132 @@
#' usamap + coord_map(project="stereographic")
#' usamap + coord_map(project="conic", lat0 = 30)
#' usamap + coord_map(project="bonne", lat0 = 50)
-CoordMap <- proto(Coord, {
- objname <- "map"
+#' }
+coord_map <- function(projection="mercator", ..., orientation = NULL, xlim = NULL, ylim = NULL) {
+ try_require("mapproj")
+ coord(
+ projection = projection,
+ orientation = orientation,
+ xlim = xlim,
+ ylim = ylim,
+ params = list(...),
+ subclass = "map"
+ )
+}
- new <- function(., projection="mercator", ..., orientation = NULL, xlim = NULL, ylim = NULL) {
- try_require("mapproj")
- .$proto(
- projection = projection,
- orientation = orientation,
- xlim = xlim,
- ylim = ylim,
- params = list(...)
- )
- }
-
- muncher <- function(.) TRUE
+#' @S3method coord_transform map
+coord_transform.map <- function(coord, data, details) {
+ trans <- mproject(coord, data$x, data$y, details$orientation)
+ out <- cunion(trans[c("x", "y")], data)
- transform <- function(., data, details) {
- trans <- .$mproject(data$x, data$y, details$orientation)
- out <- cunion(trans[c("x", "y")], data)
-
- out$x <- rescale(out$x, 0:1, details$x.range)
- out$y <- rescale(out$y, 0:1, details$y.range)
- out
- }
+ out$x <- rescale(out$x, 0:1, details$x.range)
+ out$y <- rescale(out$y, 0:1, details$y.range)
+ out
+}
+mproject <- function(coord, x, y, orientation) {
+ suppressWarnings(mapproject(x, y,
+ projection = coord$projection,
+ parameters = coord$params,
+ orientation = orientation
+ ))
+}
+
+#' @S3method coord_distance map
+coord_distance.map <- function(coord, x, y, details) {
+ max_dist <- dist_central_angle(details$x.raw, details$y.raw)
+ dist_central_angle(x, y) / max_dist
+}
+
+#' @S3method coord_aspect map
+coord_aspect.map <- function(coord, ranges) {
+ diff(ranges$y.range) / diff(ranges$x.range)
+}
+
+#' @S3method coord_train map
+coord_train.map <- function(coord, scales) {
+ x.raw <- coord$xlim %||% scale_dimension(scales$x)
+ y.raw <- coord$ylim %||% scale_dimension(scales$y)
+ orientation <- coord$orientation %||% c(90, 0, mean(x.raw))
- distance <- function(., x, y, details) {
- max_dist <- dist_central_angle(details$x.raw, details$y.raw)
- dist_central_angle(x, y) / max_dist
- }
+ # Increase chances of creating valid boundary region
+ grid <- expand.grid(
+ x = seq(x.raw[1], x.raw[2], length = 50),
+ y = seq(y.raw[1], y.raw[2], length = 50)
+ )
+ range <- mproject(coord, grid$x, grid$y, orientation)$range
- compute_aspect <- function(., ranges) {
- diff(ranges$y.range) / diff(ranges$x.range)
- }
+ x.range <- range[1:2]
+ x.major <- scale_breaks(scales$x)
+ x.minor <- scale_breaks_minor(scales$x)
+ x.labels <- scale_labels(scales$x, x.major)
+
+ y.range <- range[3:4]
+ y.major <- scale_breaks(scales$y)
+ y.minor <- scale_breaks_minor(scales$y)
+ y.labels <- scale_labels(scales$y, y.major)
+ list(
+ x.raw = x.raw, y.raw = y.raw, orientation = orientation,
+ x.range = x.range, y.range = y.range,
+ x.major = x.major, x.minor = x.minor, x.labels = x.labels,
+ y.major = y.major, y.minor = y.minor, y.labels = y.labels
+ )
+}
+
+#' @S3method coord_render_bg map
+coord_render_bg.map <- function(coord, details, theme) {
+ xrange <- expand_range(details$x.raw, 0.2)
+ yrange <- expand_range(details$y.raw, 0.2)
+ xgrid <- with(details, expand.grid(
+ y = c(seq(yrange[1], yrange[2], len = 50), NA),
+ x = x.major
+ ))
+ ygrid <- with(details, expand.grid(
+ x = c(seq(xrange[1], xrange[2], len = 50), NA),
+ y = y.major
+ ))
- mproject <- function(., x, y, orientation) {
- suppressWarnings(do.call("mapproject", list(
- data.frame(x = x, y = y),
- projection = .$projection,
- parameters = .$params,
- orientation = orientation
- )))
- }
+ xlines <- coord_transform(coord, xgrid, details)
+ ylines <- coord_transform(coord, ygrid, details)
- compute_ranges <- function(., scales) {
- x.raw <- .$xlim %||% scale_dimension(scales$x)
- y.raw <- .$ylim %||% scale_dimension(scales$y)
- orientation <- .$orientation %||% c(90, 0, mean(x.raw))
-
- # Increase chances of creating valid boundary region
- grid <- expand.grid(
- x = seq(x.raw[1], x.raw[2], length = 50),
- y = seq(y.raw[1], y.raw[2], length = 50)
+ ggname("grill", grobTree(
+ theme_render(theme, "panel.background"),
+ theme_render(
+ theme, "panel.grid.major", name = "x",
+ xlines$x, xlines$y, default.units = "native"
+ ),
+ theme_render(
+ theme, "panel.grid.major", name = "y",
+ ylines$x, ylines$y, default.units = "native"
)
- range <- .$mproject(grid$x, grid$y, orientation)$range
-
- x.range <- range[1:2]
- x.major <- scale_breaks(scales$x)
- x.minor <- scale_breaks_minor(scales$x)
- x.labels <- scale_labels(scales$x, x.major)
+ ))
+}
- y.range <- range[3:4]
- y.major <- scale_breaks(scales$y)
- y.minor <- scale_breaks_minor(scales$y)
- y.labels <- scale_labels(scales$y, y.major)
-
- list(
- x.raw = x.raw, y.raw = y.raw, orientation = orientation,
- x.range = x.range, y.range = y.range,
- x.major = x.major, x.minor = x.minor, x.labels = x.labels,
- y.major = y.major, y.minor = y.minor, y.labels = y.labels
- )
- }
+#' @S3method coord_render_axis_h map
+coord_render_axis_h.map <- function(coord, details, theme) {
+ x_intercept <- with(details, data.frame(
+ x = x.major,
+ y = y.raw[1]
+ ))
+ pos <- coord_transform(coord, x_intercept, details)
- guide_background <- function(., details, theme) {
- xrange <- expand_range(details$x.raw, 0.2)
- yrange <- expand_range(details$y.raw, 0.2)
- xgrid <- with(details, expand.grid(
- y = c(seq(yrange[1], yrange[2], len = 50), NA),
- x = x.major
- ))
- ygrid <- with(details, expand.grid(
- x = c(seq(xrange[1], xrange[2], len = 50), NA),
- y = y.major
- ))
-
- xlines <- .$transform(xgrid, details)
- ylines <- .$transform(ygrid, details)
-
- ggname("grill", grobTree(
- theme_render(theme, "panel.background"),
- theme_render(
- theme, "panel.grid.major", name = "x",
- xlines$x, xlines$y, default.units = "native"
- ),
- theme_render(
- theme, "panel.grid.major", name = "y",
- ylines$x, ylines$y, default.units = "native"
- )
- ))
- }
-
- guide_axis_h <- function(., details, theme) {
- x_intercept <- with(details, data.frame(
- x = x.major,
- y = y.raw[1]
- ))
- pos <- .$transform(x_intercept, details)
-
- guide_axis(pos$x, details$x.labels, "bottom", theme)
- }
- guide_axis_v <- function(., details, theme) {
- x_intercept <- with(details, data.frame(
- x = x.raw[1],
- y = y.major
- ))
- pos <- .$transform(x_intercept, details)
-
- guide_axis(pos$y, details$y.labels, "left", theme)
- }
-
+ guide_axis(pos$x, details$x.labels, "bottom", theme)
+}
+#' @S3method coord_render_axis_v map
+coord_render_axis_v.map <- function(coord, details, theme) {
+ x_intercept <- with(details, data.frame(
+ x = x.raw[1],
+ y = y.major
+ ))
+ pos <- coord_transform(coord, x_intercept, details)
+
+ guide_axis(pos$y, details$y.labels, "left", theme)
+}
- # Documentation -----------------------------------------------
- icon <- function(.) {
- nz <- data.frame(map("nz", plot=FALSE)[c("x","y")])
- nz$x <- nz$x - min(nz$x, na.rm=TRUE)
- nz$y <- nz$y - min(nz$y, na.rm=TRUE)
- nz <- nz / max(nz, na.rm=TRUE)
- linesGrob(nz$x, nz$y, default.units="npc")
- }
-})
+icon.map <- function(.) {
+ nz <- data.frame(map("nz", plot=FALSE)[c("x","y")])
+ nz$x <- nz$x - min(nz$x, na.rm=TRUE)
+ nz$y <- nz$y - min(nz$y, na.rm=TRUE)
+ nz <- nz / max(nz, na.rm=TRUE)
+ linesGrob(nz$x, nz$y, default.units="npc")
+}
View
20 R/coord-munch.r
@@ -1,3 +1,23 @@
+coord_munch <- function(coord, data, range, segment_length = 0.01) {
+ if (is.linear(coord)) return(coord_transform(coord, data, range))
+
+ # Convert any infinite locations into max/min
+ # Only need to work with x and y because for munching, those are the
+ # only position aesthetics that are transformed
+ data$x[data$x == -Inf] <- range$x.range[1]
+ data$x[data$x == Inf] <- range$x.range[2]
+ data$y[data$y == -Inf] <- range$y.range[1]
+ data$y[data$y == Inf] <- range$y.range[2]
+
+ # Calculate distances using coord distance metric
+ dist <- coord_distance(coord, data$x, data$y, range)
+ dist[data$group[-1] != data$group[-nrow(data)]] <- NA
+
+ # Munch and then transform result
+ munched <- munch_data(data, dist, segment_length)
+ coord_transform(coord, munched, range)
+}
+
# For munching, only grobs are lines and polygons: everything else is
# transfomed into those special cases by the geom.
#
View
325 R/coord-polar.r
@@ -3,7 +3,6 @@
#' The polar coordinate system is most commonly used for pie charts, which
#' are a stacked bar chart in polar coordinates.
#'
-#' @name coord_polar
#' @param theta variable to map angle to (\code{x} or \code{y})
#' @param start offset of starting point from 12 o'clock in radians
#' @param direction 1, clockwise; -1, anticlockwise
@@ -52,183 +51,187 @@
#' doh + geom_bar(width = 1) + coord_polar()
#' # Race track plot
#' doh + geom_bar(width = 0.9, position = "fill") + coord_polar(theta = "y")
-CoordPolar <- proto(Coord, {
- objname <- "polar"
-
- new <- function(., theta="x", start = 0, direction = 1, expand = FALSE) {
- theta <- match.arg(theta, c("x", "y"))
- r <- if (theta == "x") "y" else "x"
-
- c(
- .$proto(
- theta = theta, r = r,
- start = start, direction = sign(direction),
- expand = expand
- ),
- list(opts(aspect.ratio = 1))
- )
- }
+coord_polar <- function(theta = "x", start = 0, direction = 1, expand = FALSE) {
+ theta <- match.arg(theta, c("x", "y"))
+ r <- if (theta == "x") "y" else "x"
- distance <- function(., x, y, details) {
- max_dist <- 2*pi*abs(diff(details$r.range))
-
- if (.$theta == "x") {
- r <- y
- theta <- .$theta_rescale_no_clip(x, details)
- } else {
- r <- x
- theta <- .$theta_rescale_no_clip(y, details)
- }
- px <- r*cos(theta)
- py <- r*sin(theta)
- pz <- theta*r
+ coord(
+ theta = theta, r = r,
+ start = start, direction = sign(direction),
+ expand = expand,
+ subclass = "polar"
+ )
+}
- sqrt(diff(px)^2+diff(py)^2+diff(pz)^2) / max_dist
- }
+#' @S3method coord_aspect polar
+coord_aspect.polar <- function(coord, details) 1
- compute_ranges <- function(., scales) {
- if (.$expand) {
- x.range <- scale_dimension(scales$x)
- y.range <- scale_dimension(scales$y)
- } else {
- x.range <- scale_dimension(scales$x, c(0, 0))
- y.range <- scale_dimension(scales$y, c(0, 0))
- }
+#' @S3method coord_distance polar
+coord_distance.polar <- function(coord, x, y, details) {
+ max_dist <- 2 * pi * abs(diff(details$r.range))
+
+ if (coord$theta == "x") {
+ r <- y
+ theta <- theta_rescale_no_clip(coord, x, details)
+ } else {
+ r <- x
+ theta <- theta_rescale_no_clip(coord, y, details)
+ }
+ px <- r * cos(theta)
+ py <- r * sin(theta)
+ pz <- theta * r
- x.major <- scale_breaks(scales$x)
- x.minor <- scale_breaks_minor(scales$x)
- x.labels <- scale_labels(scales$x, x.major)
+ sqrt(diff(px) ^ 2 + diff(py) ^ 2 + diff(pz) ^ 2) / max_dist
+}
- y.major <- scale_breaks(scales$y)
- y.minor <- scale_breaks_minor(scales$y)
- y.labels <- scale_labels(scales$y, y.major)
-
- details <- list(
- x.range = x.range, y.range = y.range,
- x.major = x.major, x.minor = x.minor, x.labels = x.labels,
- y.major = y.major, y.minor = y.minor, y.labels = y.labels
- )
-
- if (.$theta == "y") {
- names(details) <- gsub("x\\.", "r.", names(details))
- names(details) <- gsub("y\\.", "theta.", names(details))
- } else {
- names(details) <- gsub("x\\.", "theta.", names(details))
- names(details) <- gsub("y\\.", "r.", names(details))
- }
- details
+#' @S3method coord_train polar
+coord_train.polar <- function(coord, scales) {
+ if (coord$expand) {
+ x.range <- scale_dimension(scales$x)
+ y.range <- scale_dimension(scales$y)
+ } else {
+ x.range <- scale_dimension(scales$x, c(0, 0))
+ y.range <- scale_dimension(scales$y, c(0, 0))
}
- rename_data <- function(., data) {
- if (.$theta == "y") {
- rename(data, c("y" = "theta", "x" = "r"))
- } else {
- rename(data, c("y" = "r", "x" = "theta"))
- }
- }
+ x.major <- scale_break_positions(scales$x)
+ x.minor <- scale_breaks_minor(scales$x)
+ x.labels <- scale_labels(scales$x, x.major)
- theta_rescale_no_clip <- function(., x, details) {
- rotate <- function(x) (x + .$start) * .$direction
- rotate(rescale(x, c(0, 2 * pi), details$theta.range))
+ y.major <- scale_break_positions(scales$y)
+ y.minor <- scale_breaks_minor(scales$y)
+ y.labels <- scale_labels(scales$y, y.major)
+
+ details <- list(
+ x.range = x.range, y.range = y.range,
+ x.major = x.major, x.minor = x.minor, x.labels = x.labels,
+ y.major = y.major, y.minor = y.minor, y.labels = y.labels
+ )
+
+ if (coord$theta == "y") {
+ names(details) <- gsub("x\\.", "r.", names(details))
+ names(details) <- gsub("y\\.", "theta.", names(details))
+ } else {
+ names(details) <- gsub("x\\.", "theta.", names(details))
+ names(details) <- gsub("y\\.", "r.", names(details))
}
- theta_rescale <- function(., x, details) {
- rotate <- function(x) (x + .$start) %% (2 * pi) * .$direction
- rotate(rescale(x, c(0, 2 * pi), details$theta.range))
- }
-
- r_rescale <- function(., x, details) {
- rescale(x, c(0, 0.4), details$r.range)
+ details
+}
+
+rename_data <- function(coord, data) {
+ if (coord$theta == "y") {
+ rename(data, c("y" = "theta", "x" = "r"))
+ } else {
+ rename(data, c("y" = "r", "x" = "theta"))
}
+}
- muncher <- function(.) TRUE
- transform <- function(., data, details) {
- data <- .$rename_data(data)
-
- data <- within(data, {
- r <- .$r_rescale(r, details)
- theta <- .$theta_rescale(theta, details)
+theta_rescale_no_clip <- function(coord, x, details) {
+ rotate <- function(x) (x + coord$start) * coord$direction
+ rotate(rescale(x, c(0, 2 * pi), details$theta.range))
+}
- x <- r * sin(theta) + 0.5
- y <- r * cos(theta) + 0.5
- })
- }
+theta_rescale <- function(coord, x, details) {
+ rotate <- function(x) (x + coord$start) %% (2 * pi) * coord$direction
+ rotate(rescale(x, c(0, 2 * pi), details$theta.range))
+}
- guide_axis_v <- function(., details, theme) {
- guide_axis(.$r_rescale(details$r.major, details) + 0.5, details$r.labels, "left", theme)
- }
- guide_axis_h <- function(., details, theme) {
- guide_axis(NA, "", "bottom", theme)
- }
+r_rescale <- function(coord, x, details) {
+ rescale(x, c(0, 0.4), details$r.range)
+}
+
+#' @S3method coord_transform polar
+coord_transform.polar <- function(coord, data, details) {
+ data <- rename_data(coord, data)
+ data <- within(data, {
+ r <- r_rescale(coord, r, details)
+ theta <- theta_rescale(coord, theta, details)
+
+ x <- r * sin(theta) + 0.5
+ y <- r * cos(theta) + 0.5
+ })
+}
+
+#' @S3method coord_render_axis_v polar
+coord_render_axis_v.polar <- function(coord, details, theme) {
+ x <- r_rescale(coord,details$r.major, details) + 0.5
+ guide_axis(x, details$r.labels, "left", theme)
+}
+#' @S3method coord_render_axis_h polar
+coord_render_axis_h.polar <- function(coord, details, theme) {
+ guide_axis(NA, "", "bottom", theme)
+}
+
+#' @S3method coord_render_bg polar
+coord_render_bg.polar <- function(coord, details, theme) {
+ details <- rename_data(coord, details)
- guide_background <- function(., details, theme) {
- details <- .$rename_data(details)
-
- theta <- .$theta_rescale(details$theta.major, details)
- thetamin <- .$theta_rescale(details$theta.minor, details)
- thetafine <- seq(0, 2 * pi, length=100)
-
- r <- 0.4
- rfine <- c(.$r_rescale(details$r.major, details), 0.45)
-
- ggname("grill", grobTree(
- theme_render(theme, "panel.background"),
- if (length(labels) > 0) theme_render(
- theme, "panel.grid.major", name = "angle",
- x = c(rbind(0, 0.45 * sin(theta))) + 0.5,
- y = c(rbind(0, 0.45 * cos(theta))) + 0.5,
- id.lengths = rep(2, length(theta)),
- default.units="native"
- ),
- theme_render(
- theme, "panel.grid.minor", name = "angle",
- x = c(rbind(0, 0.45 * sin(thetamin))) + 0.5,
- y = c(rbind(0, 0.45 * cos(thetamin))) + 0.5,
- id.lengths = rep(2, length(thetamin)),
- default.units="native"
- ),
-
- theme_render(
- theme, "panel.grid.major", name = "radius",
- x = rep(rfine, each=length(thetafine)) * sin(thetafine) + 0.5,
- y = rep(rfine, each=length(thetafine)) * cos(thetafine) + 0.5,
- id.lengths = rep(length(thetafine), length(rfine)),
- default.units="native"
- )
- ))
- }
+ theta <- theta_rescale(coord, details$theta.major, details)
+ thetamin <- theta_rescale(coord, details$theta.minor, details)
+ thetafine <- seq(0, 2 * pi, length=100)
+
+ r <- 0.4
+ rfine <- c(r_rescale(coord, details$r.major, details), 0.45)
- guide_foreground <- function(., details, theme) {
- theta <- .$theta_rescale(details$theta.major, details)
- labels <- details$theta.labels
+ ggname("grill", grobTree(
+ theme_render(theme, "panel.background"),
+ if (length(labels) > 0) theme_render(
+ theme, "panel.grid.major", name = "angle",
+ x = c(rbind(0, 0.45 * sin(theta))) + 0.5,
+ y = c(rbind(0, 0.45 * cos(theta))) + 0.5,
+ id.lengths = rep(2, length(theta)),
+ default.units="native"
+ ),
+ theme_render(
+ theme, "panel.grid.minor", name = "angle",
+ x = c(rbind(0, 0.45 * sin(thetamin))) + 0.5,
+ y = c(rbind(0, 0.45 * cos(thetamin))) + 0.5,
+ id.lengths = rep(2, length(thetamin)),
+ default.units="native"
+ ),
- # Combine the two ends of the scale if they are close
- theta <- theta[!is.na(theta)]
- ends_apart <- (theta[length(theta)] - theta[1]) %% (2*pi)
- if (ends_apart < 0.05) {
- n <- length(labels)
- if (is.expression(labels)) {
- combined <- substitute(paste(a, "/", b),
- list(a = labels[[1]], b = labels[[n]]))
- } else {
- combined <- paste(labels[1], labels[n], sep="/")
- }
- labels[[n]] <- combined
- labels <- labels[-1]
- theta <- theta[-1]
- }
-
- grobTree(
- if (length(labels) > 0) theme_render(
- theme, "axis.text.x",
- labels, 0.45 * sin(theta) + 0.5, 0.45 * cos(theta) + 0.5,
- hjust = 0.5, vjust = 0.5,
- default.units="native"
- ),
- theme_render(theme, "panel.border")
+ theme_render(
+ theme, "panel.grid.major", name = "radius",
+ x = rep(rfine, each=length(thetafine)) * sin(thetafine) + 0.5,
+ y = rep(rfine, each=length(thetafine)) * cos(thetafine) + 0.5,
+ id.lengths = rep(length(thetafine), length(rfine)),
+ default.units="native"
)
- }
+ ))
+}
+#' @S3method coord_render_fg polar
+coord_render_fg.polar <- function(coord, details, theme) {
+ theta <- theta_rescale(coord, details$theta.major, details)
+ labels <- details$theta.labels
+
+ # Combine the two ends of the scale if they are close
+ theta <- theta[!is.na(theta)]
+ ends_apart <- (theta[length(theta)] - theta[1]) %% (2*pi)
+ if (ends_apart < 0.05) {
+ n <- length(labels)
+ if (is.expression(labels)) {
+ combined <- substitute(paste(a, "/", b),
+ list(a = labels[[1]], b = labels[[n]]))
+ } else {
+ combined <- paste(labels[1], labels[n], sep="/")
+ }
+ labels[[n]] <- combined
+ labels <- labels[-1]
+ theta <- theta[-1]
+ }
- icon <- function(.) circleGrob(r = c(0.1, 0.25, 0.45), gp=gpar(fill=NA))
-})
+ grobTree(
+ if (length(labels) > 0) theme_render(
+ theme, "axis.text.x",
+ labels, 0.45 * sin(theta) + 0.5, 0.45 * cos(theta) + 0.5,
+ hjust = 0.5, vjust = 0.5,
+ default.units="native"
+ ),
+ theme_render(theme, "panel.border")
+ )
+}
+
+
+icon <- function(.) circleGrob(r = c(0.1, 0.25, 0.45), gp=gpar(fill=NA))
View
132 R/coord-transform.r
@@ -1,6 +1,5 @@
#' Transformed cartesian coordinate system.
#'
-#' @name coord_trans
#' @param ytrans transformer for x axis
#' @param xtrans transformer for y axis
#' @export
@@ -35,84 +34,77 @@
#'
#' # With a combination of scale and coordinate transformation, it's
#' # possible to do back-transformations:
+#' library(scales)
#' qplot(carat, price, data=diamonds, log="xy") +
#' geom_smooth(method="lm") +
-#' coord_trans(x="pow10", y="pow10")
+#' coord_trans(x = exp_trans(10), y = exp_trans(10))
#' # cf.
#' qplot(carat, price, data=diamonds) + geom_smooth(method = "lm")
-CoordTrans <- proto(CoordCartesian, expr={
- objname <- "trans"
+#'
+#' # Also works with discrete scales
+#' df <- data.frame(a = abs(rnorm(26)),letters)
+#' plot <- ggplot(df,aes(a,letters)) + geom_point()
+#'
+#' plot + coord_trans(x = "log10")
+#' plot + coord_trans(x = "sqrt")
+#' plot + coord_trans(x = "sqrt", y = "reverse")
+coord_trans <- function(xtrans = "identity", ytrans = "identity") {
+ if (is.character(xtrans)) xtrans <- as.trans(xtrans)
+ if (is.character(ytrans)) ytrans <- as.trans(ytrans)
-
- new <- function(., xtrans="identity", ytrans="identity") {
- if (is.character(xtrans)) xtrans <- Trans$find(xtrans)
- if (is.character(ytrans)) ytrans <- Trans$find(ytrans)
- .$proto(xtr = xtrans, ytr = ytrans)
- }
-
- muncher <- function(.) TRUE
-
- distance <- function(., x, y, details) {
- max_dist <- dist_euclidean(details$x.range, details$y.range)
- dist_euclidean(.$xtr$transform(x), .$ytr$transform(y)) / max_dist
- }
+ coord(xtr = xtrans, ytr = ytrans, subclass = "trans")
+}
- transform <- function(., data, details) {
- trans_x <- function(data) .$transform_x(data, details$x.range)
- trans_y <- function(data) .$transform_y(data, details$y.range)
-
- data <- transform_position(data, trans_x, trans_y)
- transform_position(data, trim_infinite_01, trim_infinite_01)
- }
- transform_x <- function(., data, range) {
- rescale(.$xtr$transform(data), 0:1, range)
- }
- transform_y <- function(., data, range) {
- rescale(.$ytr$transform(data), 0:1, range)
- }
+#' @S3method coord_distance trans
+coord_distance.trans <- function(coord, x, y, details) {
+ max_dist <- dist_euclidean(details$x.range, details$y.range)
+ dist_euclidean(coord$xtr$transform(x), coord$ytr$transform(y)) / max_dist
+}
- compute_ranges <- function(., scales) {
- trans_range <- function(x, expand) {
- # range is necessary in case transform has flipped min and max
- expand_range(range(x, na.rm = TRUE), expand)
- }
-
- x.range <- trans_range(.$xtr$transform(scales$x$output_set()),
- scales$x$.expand)
- x.major <- .$transform_x(scales$x$input_breaks_n(), x.range)
- x.minor <- .$transform_x(scales$x$output_breaks(), x.range)
- x.labels <- scales$x$labels()
+#' @S3method coord_transform trans
+coord_transform.trans <- function(coord, data, details) {
+ trans_x <- function(data) transform_x(coord, data, details$x.range)
+ trans_y <- function(data) transform_y(coord, data, details$y.range)
+
+ data <- transform_position(data, trans_x, trans_y)
+ transform_position(data, trim_infinite_01, trim_infinite_01)
+}
+transform_x <- function(coord, x, range) {
+ rescale(coord$xtr$transform(x), 0:1, range)
+}
+transform_y <- function(coord, x, range) {
+ rescale(