forked from wang-q/fig_table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_smooth.pl
105 lines (86 loc) · 2.48 KB
/
plot_smooth.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/perl
use strict;
use warnings;
use autodie;
use Getopt::Long;
use Pod::Usage;
use Config::Tiny;
use YAML qw(Dump Load DumpFile LoadFile);
use Statistics::R;
use List::MoreUtils qw(any all uniq zip);
use Text::CSV_XS;
#----------------------------------------------------------#
# GetOpt section
#----------------------------------------------------------#
my $file;
my $tag;
my $label;
my $x_var = 'window_gc';
my $y_var = 'flag';
my $device = 'png';
my $width = 3;
my $height = 3;
my $man = 0;
my $help = 0;
GetOptions(
'help|?' => \$help,
'man' => \$man,
'f|file=s' => \$file,
'tag=s' => \$tag,
'label' => \$label,
'x_var=s' => \$x_var,
'y_var=s' => \$y_var,
'device=s' => \$device,
'width=s' => \$width,
'height=s' => \$height,
) or pod2usage(2);
pod2usage(1) if $help;
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
{
my $R = Statistics::R->new;
$R->set( 'datafile', $file );
$R->set( 'figfile', "$tag.$x_var.$device" );
$R->set( 'x_var', $x_var );
$R->set( 'y_var', $y_var );
$R->set( 'width', $width );
$R->set( 'height', $height );
$R->run(q{ library(ggplot2) });
$R->run(q{ library(scales) });
$R->run(q{ library(gridExtra) });
$R->run(
q{
plot_var <- function (plotdata, x_var, y_var) {
plot <- ggplot(plotdata, aes_string(x=x_var, y=y_var)) +
geom_point(shape=1,) +
geom_smooth(stat = "smooth", se=TRUE, size = 1) +
theme_bw(base_size = 10)
return (plot)
}}
);
$R->run(q{ plotdata <- read.csv(datafile) });
$R->run(qq{ plot <- plot_var(plotdata, x_var, y_var) });
if ($label) {
$R->run(qq{ plot <- plot + ggtitle("$tag") });
}
if ( $device =~ /pdf/ ) {
$R->run( qq{ pdf(file=figfile, width=width, height=height) } );
}
elsif ( $device =~ /jpeg|tiff/ ) {
$R->run(q{ library(R.devices) });
$R->run(
qq{ devNew("$device", file=figfile, width=width, height=height, units="in", res=300) }
);
}
elsif ( $device =~ /png/ ) {
$R->run(
qq{ png( file=figfile, width=width, height=height, units="in", res=300) }
);
}
else {
die "Unrecognized device: [$device]\n";
}
$R->run(q{ print(plot) });
$R->run(q{ dev.off() });
}
__END__
perl plot_smooth.pl -f bac_gr/Actinobacillus_pleuropneumoniae.csv -t Actinobacillus_pleuropneumoniae