覆盖具有相同因子的盒子

时间:2016-09-25 18:48:45

标签: r ggplot2 boxplot

在下图中,对于每个因子(周),有三个框enter image description here。但是,我宁愿每周都把盒子放在彼此之上。 (相同的X位置),因此,他们将占用更少的空间。

这是一个玩具数据集,代码是

use strict;
use warnings;
use v5.10;

use DBI;
use Data::UUID;

# Connect to the database.
my $dbh = DBI->connect("dbi:SQLite:dbname=test.db", "", "", { RaiseError => 1});

# Create uuid() which calls Perl to generate a uuid.
$dbh->sqlite_create_function("uuid", 0, sub { Data::UUID->new->create_str });

# Create a table using uuid() as the default.
$dbh->do(q[drop table if exists foo]);
$dbh->do(q[
    create table foo (
        id int primary key default (uuid()),
        name text
    )
]);

# Insert some rows using the default id.
$dbh->do(q[
    insert into foo (name) values ("you"), ("me")
]);

# Print out the rows.
my $rows = $dbh->selectall_arrayref(q[select * from foo]);
for my $row (@$rows) {
    say "$row->[0], $row->[1]";
}

1 个答案:

答案 0 :(得分:0)

我们需要position = "identity" alpha,看起来仍然不太理想:

ggplot(dat, aes(x = week_number, y = value, fill = condition)) + 
  geom_boxplot(position = "identity", alpha = 0.3) +

enter image description here