[Israel.pm] Radar graph

Assaf Gordon assafgordon at gmail.com
Tue Feb 19 10:26:26 PST 2013


Assaf Gordon wrote, On 02/19/2013 10:32 AM:
> Chanan Berler wrote, On 02/17/2013 12:27 PM:
>> I need to create a radar graph on my web site. I alreay tried using graphael - but found it with lots of bugs and very little of documentation. I have tried using jqplot but it has no radar kind of graph. Does anyone knows about web base graphic library (open source) that can create radar graphes?
>>
>> P. S: radar graphes are also called splice graph or spider graphes
>>
> 
> The latest "hype" is client-side graphics, with frameworks such as d3js ( http://d3js.org/ ).
> 

Or, if you're willing to bring in the "big guns", R can do radar plots, and you can call R from Perl.

The following example creates "chart.png" as a radar-plot.
It requires R, the "fmsb" R library and the Statistics::R perl module.

====
#!/usr/bin/env perl
use strict;
use warnings;
use Statistics::R;

my $output_file = "chart.png";

## Contrived example of passing Perl values to the R script
my @total_values  = ( 2.2, 3.3, 4.1 );
my @phys_values   = ( 1, 7, 14 ) ;
my @psycho_values = ( 2,2,2.8 );

my $R_script=<<"EOF";

# Radarchart example loosely based on
#   http://www.inside-r.org/packages/cran/fmsb/docs/radarchart

# Prepare Min/Max values
maxmin = data.frame(
	   total=c(5,1),
	   phys=c(15,3),
	   psycho=c(3,0) )

# assume "total_values","phys_values","psycho_values"
# are existing R vector variables (will be created by Perl before running this script)
dat = data.frame(
	total = total_values,
	phys  = phys_values,
	psycho= psycho_values );


dat = rbind(maxmin,dat)

library(fmsb)

png(filename="$output_file",width=800,height=600,units="px")
radarchart(dat,axistype=1,seg=3,plty=1,title="Perl/R RadarChart Example")
dummy=dev.off()
EOF

# Create the R object
my $R = Statistics::R->new( shared => 1 );

# Create R vector variables with the data values
$R->set("total_values", \@total_values);
$R->set("phys_values",  \@phys_values);
$R->set("psycho_values", \@psycho_values);

# Run the script
$R->run($R_script);
====


-gordon


More information about the Perl mailing list