Skip to content

Commit

Permalink
modified xyplot to use ggplot2 (it looks better) and gives the option…
Browse files Browse the repository at this point in the history
… to use line or point type
  • Loading branch information
Jacob Perkins committed Dec 23, 2010
1 parent 7dce029 commit c2ffd33
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 18 deletions.
Binary file removed .RData
Binary file not shown.
2 changes: 0 additions & 2 deletions .Rhistory

This file was deleted.

4 changes: 2 additions & 2 deletions README.textile
Expand Up @@ -21,12 +21,12 @@ Rprompt$: install.packages("ggplot2")

h2. Examples

Provided are some examples of using the templates with "Swineherd":http://github.com/Ganglion/swineherd.
Provided are some examples of using the templates with "Swineherd":http://github.com/Ganglion/swineherd. All examples make use of the "configliere":http://github.com/mrflip/configliere gem, thus using @--help@ as an option should print options specific to that plot example.

h3. XY plot

<pre><code>
./xyplot.rb data/henon.tsv
./xyplot.rb --points --width=800 --point_size=0.1 data/henon.tsv
</code></pre>

h3. Histogram
Expand Down
240 changes: 240 additions & 0 deletions data/passengers_in_out_lax_airpt.tsv
@@ -0,0 +1,240 @@
LAX 199001 2578247
LAX 199002 2405390
LAX 199003 2759512
LAX 199004 2647926
LAX 199005 2792731
LAX 199006 3053163
LAX 199007 3249687
LAX 199008 3613398
LAX 199009 2743041
LAX 199010 2739620
LAX 199011 2674560
LAX 199012 2769149
LAX 199101 2675074
LAX 199102 2295112
LAX 199103 2717236
LAX 199104 2774845
LAX 199105 2932084
LAX 199106 3101898
LAX 199107 3339165
LAX 199108 3647764
LAX 199109 2751667
LAX 199110 2818992
LAX 199111 2618129
LAX 199112 2859169
LAX 199201 2549214
LAX 199202 2324814
LAX 199203 2653186
LAX 199204 2607335
LAX 199205 2644804
LAX 199206 3182496
LAX 199207 3542068
LAX 199208 3775679
LAX 199209 2877998
LAX 199210 2704584
LAX 199211 2637113
LAX 199212 2722874
LAX 199301 2593446
LAX 199302 2294326
LAX 199303 2675426
LAX 199304 2653665
LAX 199305 2844892
LAX 199306 3020573
LAX 199307 3273756
LAX 199308 3482154
LAX 199309 2777180
LAX 199310 2899061
LAX 199311 2788684
LAX 199312 2825870
LAX 199401 2568191
LAX 199402 2363648
LAX 199403 2856057
LAX 199404 2732830
LAX 199405 2950559
LAX 199406 3181514
LAX 199407 3481062
LAX 199408 3589176
LAX 199409 2901889
LAX 199410 3101587
LAX 199411 3045185
LAX 199412 3174093
LAX 199501 2922238
LAX 199502 2621971
LAX 199503 3139880
LAX 199504 3150526
LAX 199505 3236540
LAX 199506 3482706
LAX 199507 3616695
LAX 199508 3883528
LAX 199509 3083759
LAX 199510 3238291
LAX 199511 3169676
LAX 199512 3261724
LAX 199601 3027498
LAX 199602 2982408
LAX 199603 3471674
LAX 199604 3361294
LAX 199605 3503366
LAX 199606 3700119
LAX 199607 3864276
LAX 199608 4152565
LAX 199609 3328476
LAX 199610 3498071
LAX 199611 3128353
LAX 199612 3515829
LAX 199701 3218897
LAX 199702 2907832
LAX 199703 3575448
LAX 199704 3322231
LAX 199705 3524448
LAX 199706 3714747
LAX 199707 3821946
LAX 199708 4128381
LAX 199709 3243738
LAX 199710 3352874
LAX 199711 3242039
LAX 199712 3395694
LAX 199801 3085901
LAX 199802 2809265
LAX 199803 3385067
LAX 199804 3385958
LAX 199805 3575197
LAX 199806 3706964
LAX 199807 3913963
LAX 199808 4051578
LAX 199809 3326133
LAX 199810 3448901
LAX 199811 3372814
LAX 199812 3407668
LAX 199901 3228653
LAX 199902 3018887
LAX 199903 3633624
LAX 199904 3589658
LAX 199905 3674171
LAX 199906 3861388
LAX 199907 4152600
LAX 199908 4173027
LAX 199909 3471859
LAX 199910 3734805
LAX 199911 3689073
LAX 199912 3625474
LAX 200001 3312888
LAX 200002 3286081
LAX 200003 3855457
LAX 200004 3840399
LAX 200005 3946375
LAX 200006 4156645
LAX 200007 4304224
LAX 200008 4309968
LAX 200009 3540274
LAX 200010 3734616
LAX 200011 3683111
LAX 200012 3649189
LAX 200101 3365197
LAX 200102 3117255
LAX 200103 3813024
LAX 200104 3846703
LAX 200105 3860197
LAX 200106 4142132
LAX 200107 4363769
LAX 200108 4500178
LAX 200109 2333121
LAX 200110 2692764
LAX 200111 2727071
LAX 200112 2825855
LAX 200201 2694200
LAX 200202 2545218
LAX 200203 3160067
LAX 200204 2967840
LAX 200205 3183734
LAX 200206 3390590
LAX 200207 3581558
LAX 200208 3726258
LAX 200209 2738866
LAX 200210 3093309
LAX 200211 2938504
LAX 200212 3316139
LAX 200301 2938681
LAX 200302 2593983
LAX 200303 3017103
LAX 200304 2938499
LAX 200305 3085119
LAX 200306 3404838
LAX 200307 3675806
LAX 200308 3643862
LAX 200309 2775691
LAX 200310 3001735
LAX 200311 2953351
LAX 200312 3240333
LAX 200401 2872075
LAX 200402 2788294
LAX 200403 3329576
LAX 200404 3434257
LAX 200405 3402336
LAX 200406 3706865
LAX 200407 3934679
LAX 200408 3899542
LAX 200409 3102700
LAX 200410 3364573
LAX 200411 3254806
LAX 200412 3370202
LAX 200501 3098813
LAX 200502 2809382
LAX 200503 3441230
LAX 200504 3252040
LAX 200505 3446995
LAX 200506 3662535
LAX 200507 3908398
LAX 200508 3826554
LAX 200509 3195467
LAX 200510 3300130
LAX 200511 3241685
LAX 200512 3265519
LAX 200601 3024825
LAX 200602 2803027
LAX 200603 3388636
LAX 200604 3378552
LAX 200605 3437285
LAX 200606 3655708
LAX 200607 3858347
LAX 200608 3771520
LAX 200609 3112538
LAX 200610 3329704
LAX 200611 3314977
LAX 200612 3407460
LAX 200701 3102555
LAX 200702 2865331
LAX 200703 3503042
LAX 200704 3468985
LAX 200705 3562038
LAX 200706 3797900
LAX 200707 3988593
LAX 200708 4002775
LAX 200709 3195116
LAX 200710 3405962
LAX 200711 3360368
LAX 200712 3383626
LAX 200801 3087659
LAX 200802 2933275
LAX 200803 3440388
LAX 200804 3302758
LAX 200805 3506961
LAX 200806 3686485
LAX 200807 3823658
LAX 200808 3765295
LAX 200809 2909548
LAX 200810 3103211
LAX 200811 2835422
LAX 200812 3104683
LAX 200901 2711417
LAX 200902 2527779
LAX 200903 3086979
LAX 200904 3148825
LAX 200905 3224844
LAX 200906 3480085
LAX 200907 3741757
LAX 200908 3671815
LAX 200909 3050389
LAX 200910 3267382
LAX 200911 3028839
LAX 200912 3236610
5 changes: 3 additions & 2 deletions templates/xyplot.R.erb
@@ -1,4 +1,5 @@
library(ggplot2);
d <- read.table('<%= data %>', header=FALSE, sep="\t");
png('<%= plot %>', width=<%= width %>, res=132);
plot(d$V<%= x %>, d$V<%= y %>, type='l', xlab='<%= xlab %>', ylab='<%= ylab %>');
dev.off();
p <- ggplot(d, aes(x=d$V<%= x %>, y=d$V<%= y %>)) + <% if points %> geom_point(colour=colors()[619], size=<%= size %>) <% else %> geom_line(colour=colors()[619], size=<%= size %>) <% end %> + xlab("X") + ylab("Y");
p
28 changes: 16 additions & 12 deletions xyplot.rb
Expand Up @@ -3,24 +3,28 @@
require 'swineherd'
require 'swineherd/script/r_script' ; include Swineherd::Script

Settings.define :width, :default => 1200, :description => "Plot width in pixels"
Settings.define :x, :default => 1, :description => "Column to use as x values"
Settings.define :y, :default => 2, :description => "Column to use as y values"
Settings.define :xlab, :default => "X", :description => "X label"
Settings.define :ylab, :default => "Y", :description => "Y label"
Settings.define :width, :default => 1200, :description => "Plot width in pixels"
Settings.define :x, :default => 1, :description => "Column to use as x values"
Settings.define :y, :default => 2, :description => "Column to use as y values"
Settings.define :points, :default => false, :description => "Plot defaults to line, use points instead"
Settings.define :xlab, :default => "X", :description => "X label"
Settings.define :ylab, :default => "Y", :description => "Y label"
Settings.define :point_size, :default => 1, :description => "Width of line in pixels or size of points in pixels"
Settings.resolve!

raise "No input data!" unless Settings.rest.first

plotter = RScript.new('templates/xyplot.R.erb')
plotter.output << File.basename(Settings.rest.first).gsub(File.extname(Settings.rest.first), ".png")
plotter.attributes = {
:data => Settings.rest.first,
:plot => plotter.output,
:x => Settings.x,
:y => Settings.y,
:xlab => Settings.xlab,
:ylab => Settings.ylab,
:width => Settings.width
:data => Settings.rest.first,
:plot => plotter.output,
:x => Settings.x,
:y => Settings.y,
:xlab => Settings.xlab,
:ylab => Settings.ylab,
:width => Settings.width,
:size => Settings.point_size,
:points => Settings.points
}
plotter.run true

0 comments on commit c2ffd33

Please sign in to comment.