Chart-GGPlot

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

  - New feature: geom_col().
  - Add JSON::XS to runtime requires.

0.0005      2019-06-09
  - New feature: experimental support of geom_smooth(). At present loess
    (locally weighted estimated scatterplot smoothing) and simple linear
    regression are supported. 
  - New feature: experimental support of geom_polygon().
  - New feature: experimental support for geom_rect(), geom_tile(), and
    geom_raster().
  - New feature: Layer's show_legend attribute now really has effect.
  - Bug fix: Fixed alpha handling in the plotly backend.
  - Bug fix: Now Chart::GGPlot::Stat would not die when generate data for
    data with more points for stat then for raw data.
  - Bug fix: Fixed Chart::GGPlot::Util::match() for cases where its second
    argument has BAD values.
  - Make sure Chart::GGPlot::Util::seq_n() return piddle's last element
    always be same as its $to argument.
  - Plotly backend: legend title now aligns left and supports newlines in
    legend title text.
  - Plotly backend: now hovertext is shown for scattergl plots.

0.0003      2019-05-04
  - New feature: basic support of geom_boxplot()
  - New feature: coord_flip()
  - coord_cartesian() now really supports :$xlim, :$ylim arguments.
  - Add a Chart::GGPlot::Plot::iplot() method for convenience of plotting 
    in Jupyter Notebook.
  - Chart::GGPlot::Util::dollar() behavior is now more consistant. Hope
    this can fix a unit test failure in some special environments.

examples/geom_point_01_05.pl  view on Meta::CPAN

#!/usr/bin/env perl

# Do not show legend.

use 5.016;
use warnings;

use Getopt::Long;
use Chart::GGPlot qw(:all);
use Data::Frame::Examples qw(mtcars);

my $save_as;
GetOptions( 'o=s' => \$save_as );

my $mtcars = mtcars();

my $p = ggplot(
    data    => $mtcars,
    mapping => aes( x => 'wt', y => 'mpg' )
)->geom_point(
    mapping     => aes( color => 'factor($cyl)' ),
    show_legend => 0
);

if (defined $save_as) {
    $p->save($save_as);
} else {
    $p->show();
}

examples/geom_polygon_01_02.pl  view on Meta::CPAN

#!/usr/bin/env perl

# Do not show legend.

use 5.016;
use warnings;

use Getopt::Long;
use Chart::GGPlot qw(:all);
use PDL::Core qw(pdl);

my $save_as;
GetOptions( 'o=s' => \$save_as );

examples/geom_polygon_01_02.pl  view on Meta::CPAN

            1,    1.5, 2.2, 2.1, 1.7, 2.1, 3.2, 2.8, 2.1, 2.2, 3.3, 3.2
        ),
    ]
);

my $p = ggplot(
    data    => $datapoly,
    mapping => aes( x => 'x', y => 'y' )
)->geom_polygon(
    mapping     => aes( fill => 'value', group => 'id' ),
    show_legend => 0
);

if ( defined $save_as ) {
    $p->save($save_as);
}
else {
    $p->show();
}

lib/Chart/GGPlot/Backend/Plotly.pm  view on Meta::CPAN

    my %discrete_scales = map {
        my $scale = $_;
        if ( $scale->isa('Chart::GGPlot::Scale::Discrete') ) {
            map { $_ => $scale } @{ $scale->aesthetics };
        }
        else {
            ();
        }
    } @{ $plot->scales->non_position_scales->scales };

    # variables that produce multiple traces and deserve their own legend entries
    my @split_legend = map { "${_}_raw" } ( sort keys %discrete_scales );
    $log->debugf( "Variables that would cause legend be splitted : %s",
        Dumper( \@split_legend ) )
      if $log->is_debug;

    my $split_by =
      [ uniq( @split_legend, @{ $self->_split_on( $class_geom_impl, $data ) } )
      ];

    my $split_vars = $split_by->intersect($data->names);

    my $hover_text_aes;     # which aes shall be displayed in hover text?
    {
        # While $plot->labels also looks like containing what we need,
        # actually it be cleared or set to other values, so it can't
        # really be used for generating the hovertext. Here we would
        # get the aes from $layer->mapping and $layer->stat.

lib/Chart/GGPlot/Backend/Plotly.pm  view on Meta::CPAN

            };

            my $splitted = $d->split($fac);
            @splitted_sorted =
              map { $splitted->{$_} } sort { $a cmp $b } keys %$splitted;
        }
        else {
            push @splitted_sorted, $d;
        }

        my $showlegend = @split_legend->intersect( $data->names )->length > 0;
        return @splitted_sorted->map(
            sub {
                my ($d) = @_;

                my $traces = $class_geom_impl->to_traces($d, $params, $plot);
                for my $trace (@$traces) {
                    my $legend_key = join(
                        ', ',
                        map {
                            if ( $d->exists($_) ) {
                                my $col_data = $d->at($_);
                                $col_data->slice(pdl(0))->as_pdlsv->at(0);
                            }
                            else {
                                ();
                            }
                        } @split_legend
                    );
                    $trace->name($legend_key);

                    # some types like heatmap may not have below methods
                    if ( $trace->can('showlegend') ) {
                        $trace->legendgroup($legend_key);
                        $trace->showlegend($showlegend);
                    }
                }
                return @$traces;
            }
        );
    };

    my $splitted_data = $data->split( $data->at('PANEL') );
    my $splitted_prestats_data =
      $prestats_data->split( $prestats_data->at('PANEL') );

lib/Chart/GGPlot/Backend/Plotly.pm  view on Meta::CPAN


    my $marker = Chart::Plotly::Trace::Scatter::Marker->new(
        color      => [ 0, 1 ],
        colorscale => \@colorscale,
        colorbar   => Chart::Plotly::Trace::Scatter::Marker::Colorbar->new(
            title =>
              Chart::Plotly::Trace::Scatter::Marker::Colorbar::Title->new(
                text => $guide->title,
                side => 'top'
              ),
            # R's default is 1.2 "lines" for "legend.key.size".
            # We don't support the grid unit system now (maybe in future
            # we can develop it on Graphics::Grid::Unit), now we just
            # leave it be for plotly to use its default.
            #thickness => 30,
            tickmode => 'array',
            ticktext => $ticktext,
            tickvals => $tickvals,
            ticklen  => 2,
            len      => 0.5,
        ),
    );

    return Chart::Plotly::Trace::Scatter->new(
        x          => [0],
        y          => [0],
        type       => 'scatter',
        mode       => 'markers',
        opacity    => 0,
        hoverinfo  => 'none',
        showlegend => 0,
        marker     => $marker,
    );
}

method _to_plotly ($plot_built) {
    my $plot   = $plot_built->plot;
    my $layers = $plot->layers;
    my $layout = $plot_built->layout;

    my $plotly = Chart::Plotly::Plot->new();

lib/Chart/GGPlot/Backend/Plotly.pm  view on Meta::CPAN

    } # for (qw(x y))

    # guides
    my $gdefs = $plot->guides->build(
        $plot->scales,
        labels          => $plot->labels,
        layers          => $layers,
        default_mapping => $plot->mapping
    );

    # if $gdefs is empty, then no legend is displayed.
    my $global_showlegend = !!@$gdefs;

    my %seen_legendgroup;
    for my $i ( 0 .. $#$layers ) {
        my $layer = $layers->[$i];
        my $data  = $plot_built->layer_data($i);
        my $prestats_data  = $plot_built->layer_prestats_data($i);

        $log->debug( "data at layer $i:\n" . $data->string ) if $log->is_debug;

        my $traces =
          $self->layer_to_traces( $layer, $data, $prestats_data,
            $layout, $plot );

        for my $panel (@$traces) {
            for my $trace (@$panel) {
                if ( $trace->can('showlegend') ) {
                    if ( not $global_showlegend ) {
                        $trace->showlegend(0);
                    }
                    elsif ( $seen_legendgroup{ $trace->legendgroup }++ ) {

                        # for traces of same legend group, show legend for
                        # only the first one of them.
                        $trace->showlegend(0);
                    }
                }

                $plotly->add_trace($trace);
            }

            if ( List::AllUtils::any { $_->$_call_if_can('showlegend') }
                @$panel )
            {
                $plotly_layout{showlegend} = JSON::true;

                # legend title
                #
                # TODO: See if plotly will officially support legend title
                #  https://github.com/plotly/plotly.js/issues/276
                my $br = br();
                my $legend_titles =
                  join( $br, map { $_->title =~ s/\n/$br/gr; } @$gdefs );

                my $annotations = $plotly_layout{annotations} //= [];
                push @$annotations,
                  {
                    x         => 1.02,
                    y         => 1,
                    align     => 'left',
                    xanchor   => 'left',
                    yanchor   => 'bottom',
                    text      => $legend_titles,
                    showarrow => JSON::false,
                    xref      => 'paper',
                    yref      => 'paper',
                  };

                # Default right margin is too small for legend title.
                #
                # TODO: How to automatically calc the margin?
                #  May need to use libraries like Cairo for text width?
                #  Best if plotly can natively support legend title.
                $plotly_layout{margin} = { r => 150 };
            }
        }
    }

    # Above operations already ensures for each legend group there be only
    #  one legend item. So there is no need to keep legendgroup gap, then
    #  it looks better to me compared with having the default gap.
    $plotly_layout{legend} = { tracegroupgap => 0 };

    $plotly_layout{hovermode} = 'closest';
    $plotly_layout{barmode} = $barmode // 'relative';
    
    # border
    my $el_panel_border = $theme->at('panel_border');
    unless ( not defined $el_panel_border or $el_panel_border->is_blank ) {
        $plotly_layout{shapes} = [
            {
                type      => 'rect',

lib/Chart/GGPlot/Backend/Plotly.pm  view on Meta::CPAN

                xref => 'paper',
                x0   => 0,
                x1   => 1,
                yref => 'paper',
                y0   => 0,
                y1   => 1,
            }
        ];
    }

    if ( $theme->at('legend_position') eq 'none' ) {
        $plotly_layout{showlegend} = JSON::false;
    }

    # colorbar
    my ($colorbar) =
      grep { $_->$_DOES('Chart::GGPlot::Guide::Colorbar') } @$gdefs;
    if ($colorbar) {
        my $colorbar_trace = $self->_colorbar_to_trace($colorbar);
        $plotly->add_trace($colorbar_trace);
    }

lib/Chart/GGPlot/Geom.pm  view on Meta::CPAN

  Chart::GGPlot::HasDefaultAes
  Chart::GGPlot::HasNonMissingAes
  Chart::GGPlot::HasParams
  Chart::GGPlot::HasCollectibleFunctions
);

classmethod optional_aes() { [] }

method setup_data ($data, $params) { $data }

# Renders a single legend key.
sub draw_key { return draw_key_point(@_) }

method handle_na ( $data, $params ) {
    return remove_missing(
        $data,
        na_rm => $params->at('na_rm'),
        vars  => [ @{ $self->required_aes }, @{ $self->non_missing_aes } ],
        name  => $self->name
    );
}

lib/Chart/GGPlot/Geom/Bar.pm  view on Meta::CPAN


has '+non_missing_aes' => ( default => sub { [qw(xmin xmax ymin ymax)] } );

classmethod required_aes() { [qw(x y)] }
classmethod extra_params() { [qw(na_rm width)] }

my $geom_bar_pod = layer_func_pod(<<'EOT');

        geom_bar(:$mapping=undef, :$data=undef, :$stat='count',
                 :$position='stack', :$width=undef,
                 :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
                 %rest)

    The "bar" geom makes the height bar proportional to the number of cases
    in each group (or if the C<weight> aesthetic is supplied, the sum of the
    C<weights>). 
    It uses C<stat_count()> by default: it counts the number of cases at
    each x position. 

    Arguments:

lib/Chart/GGPlot/Geom/Bar.pm  view on Meta::CPAN

    =back

    See also L<Chart::GGPlot::Stat::Functions/stat_count>.

EOT

my $geom_bar_code = fun (
        :$mapping = undef, :$data = undef,
        :$stat = 'count', :$position = 'stack',
        :$width = undef, :$na_rm = false,
        :$show_legend = undef, :$inherit_aes = true,
        %rest )
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => $stat,
        geom        => 'bar',
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        params      => {
            width => $width,
            na_rm => $na_rm,
            %rest,
        },
    );
};

my $geom_histogram_pod = layer_func_pod(<<'EOT');

        geom_histogram(:$mapping=undef, :$data=undef, :$stat="bin",
                       :$position="stack", :$binwidth=undef, :$bins=undef,
                       :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
                       %rest)

    Visualise the distribution of a single continuous variable by dividing
    the x axis into bins and counting the number of observations in each
    bin. This "histogram" geom displays the counts with bars.

    =over 4

    %TMPL_COMMON_ARGS%

lib/Chart/GGPlot/Geom/Bar.pm  view on Meta::CPAN


    See also L<Chart::GGPlot::Stat::Functions/stat_bin>.

EOT

my $geom_histogram_code = fun (
        :$data = undef, :$mapping = undef,
        :$stat = "bin", :$position = "stack",
        :$binwidth = undef, :$bins = undef,
        :$na_rm = false,
        :$show_legend = undef, :$inherit_aes = true,
        %rest )
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => $stat,
        geom        => 'bar',
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        params      => {
            binwidth => $binwidth,
            bins     => $bins,
            na_rm    => $na_rm,
            pad      => false,
            %rest
        },
    );  
};

my $geom_col_pod = layer_func_pod(<<'EOT');

        geom_col(:$mapping=undef, :$data=undef, :$position="stack",
                 :$width=undef, :$na_rm=false, :$show_legend=undef,
                 :$inherit_aes=true,
                 %rest)

    Bar plot. Different from geom_bar(), geom_col() uses stat_identity():
    it leaves the data as is.

    =over 4

    %TMPL_COMMON_ARGS%

lib/Chart/GGPlot/Geom/Bar.pm  view on Meta::CPAN


    Bar width. By default, set to 90% of the resolution of the data.

    =back

EOT

my $geom_col_code = fun (
        :$data = undef, :$mapping = undef, :$position = "stack",
        :$width = undef,
        :$na_rm = false, :$show_legend = undef, :$inherit_aes = true,
        %rest )
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => 'identity',
        geom        => 'bar',
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        params      => {
            width => $width,
            na_rm => $na_rm,
            %rest,
        },
    );  
};

classmethod ggplot_functions() {

lib/Chart/GGPlot/Geom/Blank.pm  view on Meta::CPAN

our $VERSION = '0.002003'; # VERSION

with qw(Chart::GGPlot::Geom);

use Chart::GGPlot::Layer;

my $geom_blank_pod = '';
my $geom_blank_code = fun (
        :$mapping = undef, :$data = undef,
        :$stat = "identity", :$position = "identity",
        :$show_legend = undef, :$inherit_aes = true,
        %rest )
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => $stat,
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        check_aes   => false,
        geom        => 'blank',
        params      => \%rest,
    );
};

classmethod ggplot_functions() {
    return [
        {

lib/Chart/GGPlot/Geom/Boxplot.pm  view on Meta::CPAN

my $geom_boxplot_pod = layer_func_pod(<<'EOT');

        geom_boxplot(:$mapping=undef, :$data=undef, 
                     :$stat='boxplot', :$position='dodge2',
                     :$outlier_color=undef, :$outlier_colour=undef,
                     :$outlier_fill=undef, :$outlier_shape=undef,
                     :$outlier_size=1.5, :$outlier_stroke=undef,
                     :$outlier_alpha=undef,
                     :$notch=false, :$notchwidth=0.25,
                     :$varwidth=false, :$na_rm=false,
                     :$show_legend=undef, :$inherit_aes=true,
                     %rest)

    The boxplot compactly displays the distribution of a continuous
    variable. It visualises five summary statistics (the median, two hinges
    and two whiskers), and all "outlying" points individually.

    Arguments:

    =over 4

lib/Chart/GGPlot/Geom/Boxplot.pm  view on Meta::CPAN


my $geom_boxplot_code = fun (
        :$data=undef, :$mapping=undef, 
        :$stat='boxplot', :$position='dodge2',
        :$outlier_color=undef, :$outlier_colour=undef,
        :$outlier_fill=undef, :$outlier_shape=undef,
        :$outlier_size=1.5, :$outlier_stroke=undef,
        :$outlier_alpha=undef,
        :$notch=false, :$notchwidth=0.25,
        :$varwidth=false, :$na_rm=false,
        :$show_legend=undef, :$inherit_aes=true,
        %rest )
{
    if ( not Ref::Util::is_ref($position) ) {
        if ($varwidth) {
            $position = position_dodge2( preserve => 'single' );
        }
    }
    else {
        if ( $position->preserve eq 'total' and $varwidth ) {
            warn "Can't preserve total widths when varwidth is true.";
            $position->preserve('single');
        }
    }

    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => $stat,
        geom        => 'boxplot',
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        params      => {
            outlier_color  => ( $outlier_color // $outlier_colour ),
            outlier_fill   => $outlier_fill,
            outlier_shape  => $outlier_shape,
            outlier_size   => $outlier_size,
            outlier_stroke => $outlier_stroke,
            outlier_alpha  => $outlier_alpha,
            notch          => $notch,
            notchwidth     => $notchwidth,

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

L<Chart::GGPlot::Plot> methods, to add layers into the plot object.

=head1 FUNCTIONS

=head2 geom_blank

=head2 geom_bar

    geom_bar(:$mapping=undef, :$data=undef, :$stat='count',
             :$position='stack', :$width=undef,
             :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
             %rest)

The "bar" geom makes the height bar proportional to the number of cases
in each group (or if the C<weight> aesthetic is supplied, the sum of the
C<weights>). 
It uses C<stat_count()> by default: it counts the number of cases at
each x position. 

Arguments:

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=item * $position

Position adjustment, either as a string, or the result of a call to a
position adjustment function.

=item * $na_rm

If false, the default, missing values are removed with a warning.
If true, missing values are silently removed.

=item * $show_legend

Should this layer be included in the legends?
C<undef>, the default, includes if any aesthetics are mapped.
A true scalar for never includes, and a defined false scalar for always
includes.

=item * $inherit_aes

If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

Bar width. By default, set to 90% of the resolution of the data.

=back

See also L<Chart::GGPlot::Stat::Functions/stat_count>.

=head2 geom_histogram

    geom_histogram(:$mapping=undef, :$data=undef, :$stat="bin",
                   :$position="stack", :$binwidth=undef, :$bins=undef,
                   :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
                   %rest)

Visualise the distribution of a single continuous variable by dividing
the x axis into bins and counting the number of observations in each
bin. This "histogram" geom displays the counts with bars.

=over 4

=item * $mapping

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=item * $position

Position adjustment, either as a string, or the result of a call to a
position adjustment function.

=item * $na_rm

If false, the default, missing values are removed with a warning.
If true, missing values are silently removed.

=item * $show_legend

Should this layer be included in the legends?
C<undef>, the default, includes if any aesthetics are mapped.
A true scalar for never includes, and a defined false scalar for always
includes.

=item * $inherit_aes

If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

You should always override this C<$bins> or C<$binwidth>, exploring
multiple widths to find the best to illustrate the stories in your data.

=back

See also L<Chart::GGPlot::Stat::Functions/stat_bin>.

=head2 geom_col

    geom_col(:$mapping=undef, :$data=undef, :$position="stack",
             :$width=undef, :$na_rm=false, :$show_legend=undef,
             :$inherit_aes=true,
             %rest)

Bar plot. Different from geom_bar(), geom_col() uses stat_identity():
it leaves the data as is.

=over 4

=item * $mapping

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=item * $position

Position adjustment, either as a string, or the result of a call to a
position adjustment function.

=item * $na_rm

If false, the default, missing values are removed with a warning.
If true, missing values are silently removed.

=item * $show_legend

Should this layer be included in the legends?
C<undef>, the default, includes if any aesthetics are mapped.
A true scalar for never includes, and a defined false scalar for always
includes.

=item * $inherit_aes

If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=head2 geom_boxplot

    geom_boxplot(:$mapping=undef, :$data=undef, 
                 :$stat='boxplot', :$position='dodge2',
                 :$outlier_color=undef, :$outlier_colour=undef,
                 :$outlier_fill=undef, :$outlier_shape=undef,
                 :$outlier_size=1.5, :$outlier_stroke=undef,
                 :$outlier_alpha=undef,
                 :$notch=false, :$notchwidth=0.25,
                 :$varwidth=false, :$na_rm=false,
                 :$show_legend=undef, :$inherit_aes=true,
                 %rest)

The boxplot compactly displays the distribution of a continuous
variable. It visualises five summary statistics (the median, two hinges
and two whiskers), and all "outlying" points individually.

Arguments:

=over 4

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=item * $position

Position adjustment, either as a string, or the result of a call to a
position adjustment function.

=item * $na_rm

If false, the default, missing values are removed with a warning.
If true, missing values are silently removed.

=item * $show_legend

Should this layer be included in the legends?
C<undef>, the default, includes if any aesthetics are mapped.
A true scalar for never includes, and a defined false scalar for always
includes.

=item * $inherit_aes

If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN


For a notched box plot, width of the notch relative to the body. 

=back

See also L<Chart::GGPlot::Stat::Functions/stat_boxplot>.

=head2 geom_path

    geom_path(:$mapping=undef, :$data=undef, :$stat='identity',
              :$position='identity', :$na_rm=false, :$show_legend=undef,
              :$inherit_aes=true, 
              %rest)

The "path" geom connects the observations in the order in which they
appear in the data.

=over 4

=item * $mapping

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=item * $position

Position adjustment, either as a string, or the result of a call to a
position adjustment function.

=item * $na_rm

If false, the default, missing values are removed with a warning.
If true, missing values are silently removed.

=item * $show_legend

Should this layer be included in the legends?
C<undef>, the default, includes if any aesthetics are mapped.
A true scalar for never includes, and a defined false scalar for always
includes.

=item * $inherit_aes

If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

These are often aesthetics, used to set an aesthetic to a fixed value,
like C<color =E<gt> "red", size =E<gt> 3>.
They may also be parameters to the paired geom/stat.

=back

=head2 geom_point

    geom_point(:$mapping=undef, :$data=undef, :$stat='identity',
               :$position='identity',
               :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
               %rest)

The "point" geom is used to create scatterplots.
The scatterplot is most useful for displaying the relationship between
two continuous variables.
A bubblechart is a scatterplot with a third variable mapped to the size
of points.

Arguments:

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=item * $position

Position adjustment, either as a string, or the result of a call to a
position adjustment function.

=item * $na_rm

If false, the default, missing values are removed with a warning.
If true, missing values are silently removed.

=item * $show_legend

Should this layer be included in the legends?
C<undef>, the default, includes if any aesthetics are mapped.
A true scalar for never includes, and a defined false scalar for always
includes.

=item * $inherit_aes

If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

Other arguments passed to C<Chart::GGPlot::Layer-E<gt>new()>.
These are often aesthetics, used to set an aesthetic to a fixed value,
like C<color =E<gt> "red", size =E<gt> 3>.
They may also be parameters to the paired geom/stat.

=back

=head2 geom_line

    geom_line(:$mapping=undef, :$data=undef, :$stat='identity',
              :$position='identity', :$na_rm=false, :$show_legend=undef,
              :$inherit_aes=true, 
              %rest)

The "line" geom connects the observations in the order of the variable
on the x axis.

Arguments:

=over 4

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=item * $position

Position adjustment, either as a string, or the result of a call to a
position adjustment function.

=item * $na_rm

If false, the default, missing values are removed with a warning.
If true, missing values are silently removed.

=item * $show_legend

Should this layer be included in the legends?
C<undef>, the default, includes if any aesthetics are mapped.
A true scalar for never includes, and a defined false scalar for always
includes.

=item * $inherit_aes

If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

These are often aesthetics, used to set an aesthetic to a fixed value,
like C<color =E<gt> "red", size =E<gt> 3>.
They may also be parameters to the paired geom/stat.

=back

=head2 geom_polygon

    geom_polygon(:$mapping=undef, :$data=undef,
                 :$stat='identity', :$position='identity',
                 :$na_rm=false, :$show_legend=undef,
                 :$inherit_aes=true,
                 %rest)

Polygons are very similar to paths (as drawn by C<geom_path()>)
except that the start and end points are connected and the inside is
colored by the C<fill> aesthetic. The C<group> aesthetic determines
which cases are connected together into a polygon. 

=over 4

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=item * $position

Position adjustment, either as a string, or the result of a call to a
position adjustment function.

=item * $na_rm

If false, the default, missing values are removed with a warning.
If true, missing values are silently removed.

=item * $show_legend

Should this layer be included in the legends?
C<undef>, the default, includes if any aesthetics are mapped.
A true scalar for never includes, and a defined false scalar for always
includes.

=item * $inherit_aes

If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

These are often aesthetics, used to set an aesthetic to a fixed value,
like C<color =E<gt> "red", size =E<gt> 3>.
They may also be parameters to the paired geom/stat.

=back

=head2 geom_rect

    geom_rect(:$mapping=undef, :$data=undef, :$stat='count',
              :$position='stack', :$width=undef,
              :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
              %rest)

C<geom_rect()> uses the locations of the four corners
(aethetics C<xmin>, C<xmax>, C<ymin> and C<ymax>) to define rectangles.

Arguments:

=over 4

=item * $mapping

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=item * $position

Position adjustment, either as a string, or the result of a call to a
position adjustment function.

=item * $na_rm

If false, the default, missing values are removed with a warning.
If true, missing values are silently removed.

=item * $show_legend

Should this layer be included in the legends?
C<undef>, the default, includes if any aesthetics are mapped.
A true scalar for never includes, and a defined false scalar for always
includes.

=item * $inherit_aes

If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

These are often aesthetics, used to set an aesthetic to a fixed value,
like C<color =E<gt> "red", size =E<gt> 3>.
They may also be parameters to the paired geom/stat.

=back

=head2 geom_tile

    geom_tile(:$mapping=undef, :$data=undef, :$stat='count',
              :$position='stack', :$width=undef,
              :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
              %rest)

C<geom_tile()> uses the center of the tile and its size
(aesthetics C<x>, C<y>, C<width> and C<height>) to define rectangles.

Arguments:

=over 4

=item * $mapping

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=item * $position

Position adjustment, either as a string, or the result of a call to a
position adjustment function.

=item * $na_rm

If false, the default, missing values are removed with a warning.
If true, missing values are silently removed.

=item * $show_legend

Should this layer be included in the legends?
C<undef>, the default, includes if any aesthetics are mapped.
A true scalar for never includes, and a defined false scalar for always
includes.

=item * $inherit_aes

If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

like C<color =E<gt> "red", size =E<gt> 3>.
They may also be parameters to the paired geom/stat.

=back

=head2 geom_raster

    geom_raster(:$mapping=undef, :$data=undef, :$stat='count',
                Num :$hjust=0.5, Num :$vjust=0.5,
                :$position='stack', :$width=undef,
                :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
                %rest)

C<geom_raster()> is a high performance special case of C<geom_tile()>
for when all the tiles are the same size.

Arguments:

=over 4

=item * $mapping

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=item * $position

Position adjustment, either as a string, or the result of a call to a
position adjustment function.

=item * $na_rm

If false, the default, missing values are removed with a warning.
If true, missing values are silently removed.

=item * $show_legend

Should this layer be included in the legends?
C<undef>, the default, includes if any aesthetics are mapped.
A true scalar for never includes, and a defined false scalar for always
includes.

=item * $inherit_aes

If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

like C<color =E<gt> "red", size =E<gt> 3>.
They may also be parameters to the paired geom/stat.

=back

=head2 geom_smooth

    geom_smooth(:$mapping=undef, :$data=undef,
                :$stat='smooth', :$position='identity',
                :$method='auto', :$se=true,
                :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
                %rest)

Aids the eye in seeing patterns in the presence of overplotting, by
calculating a smoothed conditional mean.

C<geom_smooth()> and C<stat_smooth()> are effectively aliases: they
both use the same arguments. Use C<stat_smooth()> if you want to
display the results with a non-standard geom.

Arguments:

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=item * $position

Position adjustment, either as a string, or the result of a call to a
position adjustment function.

=item * $na_rm

If false, the default, missing values are removed with a warning.
If true, missing values are silently removed.

=item * $show_legend

Should this layer be included in the legends?
C<undef>, the default, includes if any aesthetics are mapped.
A true scalar for never includes, and a defined false scalar for always
includes.

=item * $inherit_aes

If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

They may also be parameters to the paired geom/stat.

=back

See also L<Chart::GGPlot::Stat::Functions/stat_smooth>.

=head2 geom_text

    geom_text(:$mapping=undef, :$data=undef, :$stat='identity',
              :$position='identity',
              :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
              %rest)

C<geom_text()> adds text to the plot.

Arguments:

=over 4

=item * $mapping

lib/Chart/GGPlot/Geom/Functions.pm  view on Meta::CPAN

=item * $position

Position adjustment, either as a string, or the result of a call to a
position adjustment function.

=item * $na_rm

If false, the default, missing values are removed with a warning.
If true, missing values are silently removed.

=item * $show_legend

Should this layer be included in the legends?
C<undef>, the default, includes if any aesthetics are mapped.
A true scalar for never includes, and a defined false scalar for always
includes.

=item * $inherit_aes

If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

lib/Chart/GGPlot/Geom/Line.pm  view on Meta::CPAN

extends qw(Chart::GGPlot::Geom::Path);

our $VERSION = '0.002003'; # VERSION

use Chart::GGPlot::Layer;
use Chart::GGPlot::Util::Pod qw(layer_func_pod);

my $geom_line_pod = layer_func_pod(<<'EOT');

        geom_line(:$mapping=undef, :$data=undef, :$stat='identity',
                  :$position='identity', :$na_rm=false, :$show_legend=undef,
                  :$inherit_aes=true, 
                  %rest)

    The "line" geom connects the observations in the order of the variable
    on the x axis.

    Arguments:

    =over 4

    %TMPL_COMMON_ARGS%

    =back

EOT

my $geom_line_code = fun (
        :$mapping = undef, :$data = undef,
        :$stat = 'identity', :$position = 'identity',
        :$na_rm = false,
        :$show_legend = undef, :$inherit_aes = true,
        %rest )
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => $stat,
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        geom        => 'line',
        params      => { na_rm => $na_rm, %rest },
    );
};

classmethod ggplot_functions() {
    return [
        {
            name => 'geom_line',

lib/Chart/GGPlot/Geom/Path.pm  view on Meta::CPAN

            alpha    => NA(),
        );
    }
);

classmethod required_aes () { [qw(x y)] }

my $geom_path_pod = layer_func_pod(<<'EOT');

        geom_path(:$mapping=undef, :$data=undef, :$stat='identity',
                  :$position='identity', :$na_rm=false, :$show_legend=undef,
                  :$inherit_aes=true, 
                  %rest)

    The "path" geom connects the observations in the order in which they
    appear in the data.

    =over 4

    %TMPL_COMMON_ARGS%

    =back

EOT

my $geom_path_code = fun (
        :$mapping = undef, :$data = undef,
        :$stat = 'identity', :$position = 'identity',
        :$na_rm = false,
        :$show_legend = undef, :$inherit_aes = true,
        %rest )
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => $stat,
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        geom        => 'path',
        params      => { na_rm => $na_rm, %rest },
    );
};

classmethod ggplot_functions() {
    return [
        {
            name => 'geom_path',

lib/Chart/GGPlot/Geom/Point.pm  view on Meta::CPAN

        );
    }
);

classmethod required_aes() { [qw(x y)] }

my $geom_point_pod = layer_func_pod(<<'EOT');

        geom_point(:$mapping=undef, :$data=undef, :$stat='identity',
                   :$position='identity',
                   :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
                   %rest)

    The "point" geom is used to create scatterplots.
    The scatterplot is most useful for displaying the relationship between
    two continuous variables.
    A bubblechart is a scatterplot with a third variable mapped to the size
    of points.

    Arguments:

lib/Chart/GGPlot/Geom/Point.pm  view on Meta::CPAN

    %TMPL_COMMON_ARGS%

    =back

EOT

my $geom_point_code = fun (
        :$mapping = undef, :$data = undef,
        :$stat = 'identity', :$position = 'identity',
        :$na_rm = false,
        :$show_legend = undef, :$inherit_aes = true,
        %rest )
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => $stat,
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        geom        => 'point',
        params      => { na_rm => $na_rm, %rest },
    );
};

classmethod ggplot_functions() {
    return [
        {
            name => 'geom_point',

lib/Chart/GGPlot/Geom/Polygon.pm  view on Meta::CPAN

        );
    }   
);

classmethod required_aes() { [qw(x y)] }

my $geom_polygon_pod = layer_func_pod(<<'EOT');

        geom_polygon(:$mapping=undef, :$data=undef,
                     :$stat='identity', :$position='identity',
                     :$na_rm=false, :$show_legend=undef,
                     :$inherit_aes=true,
                     %rest)

    Polygons are very similar to paths (as drawn by C<geom_path()>)
    except that the start and end points are connected and the inside is
    colored by the C<fill> aesthetic. The C<group> aesthetic determines
    which cases are connected together into a polygon. 

    =over 4

    %TMPL_COMMON_ARGS%

    =back

EOT

my $geom_polygon_code = fun (
        :$mapping = undef, :$data = undef,
        :$stat = 'identity', :$position = 'identity',
        :$width = undef, :$na_rm = false,
        :$show_legend = undef, :$inherit_aes = true,
        %rest )
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => $stat,
        geom        => 'polygon',
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        params      => {
            na_rm => $na_rm,
            %rest,
        },
    );
};

classmethod ggplot_functions() {
    return [

lib/Chart/GGPlot/Geom/Raster.pm  view on Meta::CPAN


classmethod require_aes () { [qw(x y)] }
classmethod extra_params () { [qw(na_rm)] }
classmethod _parameters () { [qw(hjust vjust interpolate)] }

my $geom_raster_pod = layer_func_pod(<<'EOT');

        geom_raster(:$mapping=undef, :$data=undef, :$stat='count',
                    Num :$hjust=0.5, Num :$vjust=0.5,
                    :$position='stack', :$width=undef,
                    :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
                    %rest)

    C<geom_raster()> is a high performance special case of C<geom_tile()>
    for when all the tiles are the same size.

    Arguments:

    =over 4

    %TMPL_COMMON_ARGS%

    =back

EOT

my $geom_raster_code = fun(
    :$mapping = undef, :$data = undef,
    :$stat = 'identity', :$position = 'identity',
    Num :$hjust = 0.5, Num :$vjust = 0.5,
    #:$interpolate = false,
    :$na_rm = false, :$show_legend = undef, :$inherit_aes = true,
    %rest)
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => $stat,
        geom        => 'raster',
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        params      => {
            na_rm       => $na_rm,
            hjust       => $hjust,
            vjust       => $vjust,
            #interpolate => $interpolate,
            %rest
        },
    );
};

lib/Chart/GGPlot/Geom/Rect.pm  view on Meta::CPAN

        );
    }
);

classmethod required_aes() { [qw(xmin xmax ymin ymax)] };

my $geom_rect_pod = layer_func_pod(<<'EOT');

        geom_rect(:$mapping=undef, :$data=undef, :$stat='count',
                  :$position='stack', :$width=undef,
                  :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
                  %rest)

    C<geom_rect()> uses the locations of the four corners
    (aethetics C<xmin>, C<xmax>, C<ymin> and C<ymax>) to define rectangles.

    Arguments:

    =over 4

    %TMPL_COMMON_ARGS%

    =back

EOT

my $geom_rect_code = fun(
    :$mapping = undef, :$data = undef,
    :$stat = 'identity', :$position = 'identity',
    :$na_rm = false, :$show_legend = undef, :$inherit_aes = true,
    %rest)
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => $stat,
        geom        => 'rect',
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        params      => {
            na_rm => $na_rm,
            %rest
        },
    );
};

classmethod ggplot_functions () {
    return [

lib/Chart/GGPlot/Geom/Smooth.pm  view on Meta::CPAN

);

classmethod required_aes() { [qw(x y)] }
classmethod optional_aes() { [qw(ymin ymax)] }

my $geom_smooth_pod = layer_func_pod(<<'EOT');

        geom_smooth(:$mapping=undef, :$data=undef,
                    :$stat='smooth', :$position='identity',
                    :$method='auto', :$se=true,
                    :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
                    %rest)

    Aids the eye in seeing patterns in the presence of overplotting, by
    calculating a smoothed conditional mean.

    C<geom_smooth()> and C<stat_smooth()> are effectively aliases: they
    both use the same arguments. Use C<stat_smooth()> if you want to
    display the results with a non-standard geom.

    Arguments:

lib/Chart/GGPlot/Geom/Smooth.pm  view on Meta::CPAN


    See also L<Chart::GGPlot::Stat::Functions/stat_smooth>.

EOT

my $geom_smooth_code = fun (
        :$mapping = undef, :$data = undef,
        :$stat = 'smooth', :$position = 'identity',
        :$method = 'auto',
        :$se = true,
        :$na_rm = false, :$show_legend = undef, :$inherit_aes = true,
        %rest )
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => $stat,
        geom        => 'smooth',
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        params      => {
            na_rm  => $na_rm,
            se     => $se,
            method => $method,
            %rest
        },
    );  
};

lib/Chart/GGPlot/Geom/Text.pm  view on Meta::CPAN

        );
    }
);

classmethod required_aes() { [qw(x y label)] }

my $geom_text_pod = layer_func_pod(<<'EOT');

        geom_text(:$mapping=undef, :$data=undef, :$stat='identity',
                  :$position='identity',
                  :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
                  %rest)

    C<geom_text()> adds text to the plot.

    Arguments:

    =over 4

    %TMPL_COMMON_ARGS%

lib/Chart/GGPlot/Geom/Text.pm  view on Meta::CPAN

    =back

EOT

my $geom_text_code = fun(
    : $mapping     = undef,
    : $data        = undef,
    : $stat        = 'identity',
    : $position    = 'identity',
    : $na_rm       = false,
    : $show_legend = undef,
    : $inherit_aes = true,
    %rest
  )
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => $stat,
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        geom        => 'text',
        params      => { na_rm => $na_rm, %rest },
    );
};

classmethod ggplot_functions() {
    return [
        {
            name => 'geom_text',

lib/Chart/GGPlot/Geom/Tile.pm  view on Meta::CPAN

    }
);

classmethod require_aes () { [qw(x y)] }
classmethod extra_params () { [qw(na_rm)] }

my $geom_tile_pod = layer_func_pod(<<'EOT');

        geom_tile(:$mapping=undef, :$data=undef, :$stat='count',
                  :$position='stack', :$width=undef,
                  :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
                  %rest)

    C<geom_tile()> uses the center of the tile and its size
    (aesthetics C<x>, C<y>, C<width> and C<height>) to define rectangles.

    Arguments:

    =over 4

    %TMPL_COMMON_ARGS%

    =back

EOT

my $geom_tile_code = fun(
    :$mapping = undef, :$data = undef,
    :$stat = 'identity', :$position = 'identity',
    :$na_rm = false, :$show_legend = undef, :$inherit_aes = true,
    %rest)
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => $stat,
        geom        => 'tile',
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        params      => {
            na_rm => $na_rm,
            %rest
        },
    );
};

classmethod ggplot_functions () {
    return [

lib/Chart/GGPlot/Guide/Functions.pm  view on Meta::CPAN


use Chart::GGPlot::Setup;

our $VERSION = '0.002003'; # VERSION

use Chart::GGPlot::Guide::Legend;

use parent qw(Exporter::Tiny);

our @EXPORT_OK = qw(
  guide_legend 
);
our %EXPORT_TAGS = (
    'all'    => \@EXPORT_OK,
    'ggplot' => [qw(guide_legend)],
);


sub guide_legend {
    return Chart::GGPlot::Guide::Legend->new(@_);   
}


1;

__END__

=pod

lib/Chart/GGPlot/Guide/Functions.pm  view on Meta::CPAN

=head1 NAME

Chart::GGPlot::Guide::Functions - Function interface for guides

=head1 VERSION

version 0.002003

=head1 FUNCTIONS

=head2 guide_legend

    guide_legend(:$title=undef, %rest)

=head1 SEE ALSO

L<Chart::GGPlot::Guide>

=head1 AUTHOR

Stephan Loyd <sloyd@cpan.org>

=head1 COPYRIGHT AND LICENSE

lib/Chart/GGPlot/Guides.pm  view on Meta::CPAN

                );
            }

            $guide = $guide->train($scale, $output);
            next unless defined $guide;

            if (
                List::AllUtils::none {
                    my $matched =
                      $self->_matched_aes( $_, $guide, $default_mapping );
                    my $show_legend = $_->show_legend;
                    ( $matched->length > 0
                          and ( not defined $show_legend or $show_legend ) )
                }
                @$layers
              )
            {
                next;
            }

            if (defined $guide) { 
                push @gdefs, $guide;
            }

lib/Chart/GGPlot/Labels.pm  view on Meta::CPAN

package Chart::GGPlot::Labels;

# ABSTRACT: Axis, legend, and plot labels

use Chart::GGPlot::Setup;
use namespace::autoclean;

our $VERSION = '0.002003'; # VERSION

use parent qw(Chart::GGPlot::Aes);

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Chart::GGPlot::Labels - Axis, legend, and plot labels

=head1 VERSION

version 0.002003

=head1 DESCRIPTION

This class inherits L<Chart::GGPlot::Aes>.
Now it actually does nothing more than its parent class, but is just for
having its own type which is used by L<Chart::GGPlot::Plot>. 

lib/Chart/GGPlot/Layer.pm  view on Meta::CPAN

);
has aes_params => (
    is     => 'rw',
    isa    => AesMapping,
    coerce => 1,
);
has position    => ( is => 'ro', required => 1 );
has inherit_aes => ( is => 'ro', default  => sub { false } );


has show_legend => ( is => 'ro' );

around BUILDARGS( $orig, $class : @rest ) {
    my %params = @rest;
    return $class->$orig( %{ $class->_layer(%params) } );
};

classmethod _find_subclass ($super, $name) {
    return (
          $name =~ /^Chart::GGPlot::/
        ? $name
        : "Chart::GGPlot::${super}::"
          . join( '', map { ucfirst($_) } split( /_/, $name ) )
    );
}

classmethod _layer (Defined :$geom, Defined :$stat,
                    :$data = undef, :$mapping = undef,
                    Defined :$position,
                    :$params = { na_rm => false },
                    :$inherit_aes = true, :$check_aes = true,
                    :$check_param = true, :$show_legend = NA
  ) {
    $mapping //= Chart::GGPlot::Aes->new();
    unless ( defined $params->at("na_rm") ) {
        $params->set( "na_rm", "nan" );
    }

    my $find_subclass = fun( $super, $x ) {
        unless ( Ref::Util::is_ref($x) ) {  # $x is a class name
            my $subclass = $class->_find_subclass( $super, $x );
            load $subclass;

lib/Chart/GGPlot/Layer.pm  view on Meta::CPAN

        carp( "Ignoring unknown aesthetics: " . join( ", ", @extra_aes ) );
    }

    return {
        geom        => $geom,
        stat        => $stat,
        data        => $data,
        mapping     => $mapping,
        position    => $position,
        inherit_aes => $inherit_aes,
        show_legend => $show_legend,
        geom_params => $geom_params,
        stat_params => $stat_params,
        aes_params  => $aes_params,
    };
}


method string () {
    my $s = '';
    if ( $self->mapping ) {

lib/Chart/GGPlot/Layer.pm  view on Meta::CPAN


If false, overrides the default aesthetics, rather than combining with them.
This is most useful for helper functions that define both data and
aesthetics and shouldn't inherit behaviour from the default plot
specification.

=head2 params

Additional parameters to the "geom" and "stat".

=head2 show_legend

Should this layer be included in the legends?

=over 4

=item *

C<undef>, includes if any aesthetics are mapped.

=item *

A defined true scalar (non-Chart::GGPlot::Aes), never includes.

lib/Chart/GGPlot/Position/Dodge2.pm  view on Meta::CPAN


=head2 padding

Padding between elements at the same position.
Elements are shrunk by this proportion to allow space between them.
Defaults to 0.1.

=head2 reverse

If true, will reverse the default stacking order.
This is useful if you're rotating both the plot and legend. 

=head1 SEE ALSO

L<Chart::GGPlot::Position>,
L<Chart::GGPlot::Position::Dodge>,

=head1 AUTHOR

Stephan Loyd <sloyd@cpan.org>

lib/Chart/GGPlot/Position/Stack.pm  view on Meta::CPAN


=head1 DESCRIPTION

This stacks bars on top of each other.

=head1 ATTRIBUTES

=head2 reverse

If true, will reverse the default stacking order.
This is useful if you're rotating both the plot and legend.
Default is false.

=head1 SEE ALSO

L<Chart::GGPlot::Position>

=head1 AUTHOR

Stephan Loyd <sloyd@cpan.org>

lib/Chart/GGPlot/Position/Util.pm  view on Meta::CPAN

}

fun collide ($data, $width, $name, $strategy,
             :$check_width=true, :$reverse=false, %rest) {
    my $dlist =
      collide_setup( $data, $width, $name, $strategy, $check_width, $reverse );
    $data  = $dlist->{data};
    $width = $dlist->{width};

    # Reorder by x position, then on group. The default stacking order
    # reverses the group in order to match the legend order.
    $data = $data->sort( [qw(xmin group)], $reverse ? true : [ true, false ] );

    # TODO: ddply to preserve the order.
    #  So firstly DF::split() shall preserve the order.
    state $ddply = sub {
        my ( $df, $vars, $func ) = @_;

        my $ids         = $df->select_columns($vars)->id;
        my $splitted    = $df->split($ids);
        my @transformed = map { $func->($_) } values %$splitted;

lib/Chart/GGPlot/Scale.pm  view on Meta::CPAN

    is      => 'rw',
    default => sub { null; },
);

has na_value => ( is => 'rw', default => "nan" );
has expand   => ( is => 'rw', default => undef );
has name     => ( is => 'rw', default => undef );
has breaks   => ( is => 'rw', default => undef );
has labels =>
  ( is => 'rw', isa => Maybe [ Piddle | CodeRef ], default => undef );
has guide    => ( is => 'ro', default => "legend" );
has position => ( is => 'rw', isa     => PositionEnum, default => "left" );
has trans    => ( is => 'rw', isa     => InstanceOf ["Chart::GGPlot::Trans"] );

requires 'train';    # Train an individual scale from a vector of data.
requires 'transform';

requires 'get_breaks_minor';
requires 'get_labels';
requires 'break_info';
requires 'dimension';

lib/Chart/GGPlot/Scale.pm  view on Meta::CPAN

A palette function that when called with a single integer
argument (the number of levels in the scale) returns the values that
they should take.

=head2 limits

A numeric vector of length two providing limits of the scale.

=head2 name

Used as axis or legend title. If C<undef>, the default, it's taken from
the first mapping used for that aesthetic. If C<null> or C<[]>, the legend
title will be omitted.

=head2 breaks

One of

=over 4

=item *

lib/Chart/GGPlot/Scale/Functions.pm  view on Meta::CPAN

    return ($breaks, $labels);
}


fun continuous_scale (:$aesthetics, :$scale_name,
                      :$palette, :$name=undef,
                      :$breaks=undef, :$minor_breaks=undef,
                      :$labels=undef, :$limits=null(),
                      :$rescaler=\&rescale, :$oob=\&censor, :$expand=undef,
                      :$na_value='nan',
                      :$trans="identity", :$guide="legend",
                      PositionEnum :$position="left",
                      Str :$super='Chart::GGPlot::Scale::Continuous',
                      %rest
  ) {
    ($breaks, $labels) = _check_breaks_labels( $breaks, $labels );

    if (    ( defined $breaks and $breaks->isempty )
        and !is_position_aes($aesthetics)
        and $guide ne "none" )
    {

lib/Chart/GGPlot/Scale/Functions.pm  view on Meta::CPAN

        )
    );
}


fun discrete_scale (:$aesthetics, :$scale_name,
                    :$palette, :$name=undef,
                    :$breaks=undef, :$labels=undef,
                    :$limits=PDL::SV->new([]),
                    :$expand=undef, :$na_translate=true, :$na_value=undef,
                    :$drop=true, :$guide="legend",
                    PositionEnum :$position = "left",
                    Str :$super = 'Chart::GGPlot::Scale::Discrete',
                    %rest
  ) {
    ($breaks, $labels) = _check_breaks_labels( $breaks, $labels );

    if (    ( defined $breaks and $breaks->isempty )
        and !is_position_aes($aesthetics)
        and $guide ne "none" )
    {

lib/Chart/GGPlot/Scale/Functions.pm  view on Meta::CPAN

        my $scale_func      = "scale_${aes}_${trans}";
        my $continuous_func = "scale_${aes}_continuous";
        no strict 'refs';
        *{$scale_func} = sub { $continuous_func->( @_, trans => $trans ) }
    }
}


fun scale_size_continuous (:$name=undef, :$breaks=undef, :$labels=undef,
                          :$limits=[], :$range=[1, 6],
                          :$trans='identity', :$guide='legend') {
    return continuous_scale(
        pairgrep { defined $b } (
            aesthetics => 'size',
            scale_name => 'area',
            palette    => area_pal($range),
            name       => $name,
            breaks     => $breaks,
            labels     => $labels,
            limits     => $limits,
            trans      => $trans,

lib/Chart/GGPlot/Scale/Functions.pm  view on Meta::CPAN

#        :$limits = undef, :$expand = undef,
#        PositionEnum :$position = "left",
#        :$sec_axis = undef)


fun datetime_scale (:$aesthetics, :$trans, :$palette,
                    :$breaks = pretty_breaks(), :$minor_breaks = undef,
                    :$labels = undef, :$date_breaks = undef,
                    :$date_labels = undef,
                    :$date_minor_breaks = undef, :$timezone = undef,
                    :$guide = 'legend',
                    %rest) {

    # TODO: handle timezone

    if ( defined $date_breaks ) {
        $breaks = date_breaks($date_breaks);
    }
    if ( defined $date_minor_breaks ) {
        $minor_breaks = date_breaks($date_minor_breaks);
    }

lib/Chart/GGPlot/Scale/Functions.pm  view on Meta::CPAN


Find scale function by aes name and data type. The scale function is in the
form of C<scale_${aes}_${type}>, where C<$type> is decided by C<$x>.

=head2 continuous_scale

    continuous_scale (:$aesthetics, :$scale_name, :$palette, :$name=undef,
        :$breaks=undef, :$minor_breaks=undef, :$labels=undef,
        :$limits=null(), :$rescaler=\&rescale, :$oob=\&censor,
        :$expand=undef, :$na_value='nan', :$trans="identity",
        :$guide="legend", PositionEnum :$position="left",
        Str :$super='Chart::GGPlot::Scale::Continuous',
        %rest)

Continuous scale constructor.
It's internally used by the continous scales in this module.

Arguments:

=over 4

lib/Chart/GGPlot/Scale/Functions.pm  view on Meta::CPAN

The name of the scale.

=item * $palette

A palette function that when called with a numeric piddle with values
between 0 and 1 returns the corresponding values in the range the scale maps
to.

=item * $name

The name of the scale. Used as the axis or legend title.
If C<undef>, the default, the name of the scale is taken from the first
mapping used for that aesthetic.

=item * $breaks

Major breaks.

One of:

=over 8

lib/Chart/GGPlot/Scale/Functions.pm  view on Meta::CPAN

The class to use for the constructed scale.
Default is L<Chart::GGPlot::Scale::Continuous>.

=back

=head2 discrete_scale

    discrete_scale(:$aesthetics, :$scale_name, :$palette, :$name=undef,
        :$breaks=undef, :$labels=undef, :$limits=PDL::SV->new([]),
        :$expand=undef, :$na_translate=true, :$na_value=undef,
        :$drop=true, :$guide="legend", PositionEnum :$position = "left",
        Str :$super = 'Chart::GGPlot::Scale::Discrete',
        %rest)

Discrete scale constructor.
It's internally used by the discrete scales in this module.

Arguments:

=over 4

lib/Chart/GGPlot/Scale/Functions.pm  view on Meta::CPAN


The name of the scale.

=item * $palette

A palette function that when called with a single argument (the number of
levels in the scale) returns the values that they should take.

=item * $name

The name of the scale. Used as the axis or legend title.
If C<undef>, the default, the name of the scale is taken from the first
mapping used for that aesthetic.

=item * $breaks

Major breaks.

One of:

=over 8

lib/Chart/GGPlot/Stat/Bin.pm  view on Meta::CPAN

    ]
}

my $stat_bin_pod = layer_func_pod(<<'EOT');

        stat_bin(:$mapping=undef, :$data=undef,
                 :$geom="bar", :$position="stack",
                 :$binwidth=undef, :$bins=undef,
                 :$center=undef, :$boundary=undef, :$breaks=undef,
                 :$pad=false,
                 :$na_rm=false, :$show_legend='auto', :$inherit_aes=true,
                 %rest)

    Arguments:

    =over 4

    %TMPL_COMMON_ARGS%

    =item * $binwidth

lib/Chart/GGPlot/Stat/Bin.pm  view on Meta::CPAN


EOT

my $stat_bin_code = fun (
    :$mapping=undef, :$data=undef,
    :$geom="bar", :$position="stack",
    :$binwidth=undef, :$bins=undef,
    :$center=undef, :$boundary=undef, :$breaks=undef,
    :$pad=false,
    :$na_rm=false,
    :$show_legend='auto', :$inherit_aes=true,
    %rest )
{                           
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => 'bin',
        geom        => $geom,
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        params      => {
            binwidth => $binwidth,
            bins     => $bins,
            center   => $center,
            boundary => $boundary,
            breaks   => $breaks,
            pad      => $pad,
            na_rm    => $na_rm,
            %rest

lib/Chart/GGPlot/Stat/Boxplot.pm  view on Meta::CPAN

          bins binwidth boundary breaks center pad
          )
    ]
}

my $stat_boxplot_pod = layer_func_pod(<<'EOT');

        stat_boxplot(:$mapping=undef, :$data=undef,
                     :$geom='boxplot', :$position='dodge2',
                     :$coef=1.5,
                     :$na_rm=false, :$show_legend='auto', :$inherit_aes=true,
                     %rest)

    Arguments:

    =over 4

    %TMPL_COMMON_ARGS%

    =item * $coef

    Length of the whiskers as multiple of IQR. Defaults to 1.5.

    =back

EOT

my $stat_boxplot_code = fun (
        :$mapping=undef, :$data=undef,
        :$geom='boxplot', :$position='dodge2',
        :$coef=1.5, :$na_rm=false,
        :$show_legend='auto', :$inherit_aes=true,
        %rest )
{
    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => 'boxplot',
        geom        => $geom,
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        params      => {
            na_rm => $na_rm,
            coef  => $coef,
            %rest,
        }
    );
};

classmethod ggplot_functions () {

lib/Chart/GGPlot/Stat/Count.pm  view on Meta::CPAN

    }
);

classmethod required_aes() { ['x'] }

my $stat_count_pod = layer_func_pod(<<'EOT');

        stat_count(:$mapping=undef, :$data=undef,
                   :$geom='bar', :$position='stack', 
                   :$width=undef,
                   :$na_rm=false, :$show_legend=undef, :$inherit_aes=true,
                   %rest)

    Arguments:

    =over 4

    %TMPL_COMMON_ARGS%

    =item * $width

    Bar width. By default, set to 90% of the resolution of the data.

    =back

EOT

my $stat_count_code = fun (
        :$mapping = undef, :$data = undef,
        :$geom = 'bar', :$position = 'stack', 
        :$width = undef, :$na_rm = false,
        :$show_legend = undef, :$inherit_aes = true,
        %rest )
{ 
    my $params = { 
        na_rm => $na_rm,
        width => $width,
        %rest
    };  
    if ( $data->exists('y') ) { 
        die "stat_count() must not be used with a y aesthetic.";
    }   

    return Chart::GGPlot::Layer->new(
        data        => $data,
        mapping     => $mapping,
        stat        => 'count',
        geom        => $geom,
        position    => $position,
        show_legend => $show_legend,
        inherit_aes => $inherit_aes,
        params      => $params,
    );  
};

classmethod ggplot_functions() {
    return [
        {
            name => 'stat_count',
            code => $stat_count_code,



( run in 1.506 second using v1.01-cache-2.11-cpan-49f99fa48dc )