Skip to content

Commit

Permalink
add plots for distance distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Jun 11, 2024
1 parent dc2ee50 commit cab0b80
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public Integer call() throws Exception {
writeModeShare(joined, labels);

if (groups != null) {
groups.analyzeModeShare(joined, labels, (g) -> output.getPath("mode_share_per_%s.csv", g));
groups.analyzeModeShare(joined, labels, modeOrder, (g) -> output.getPath("mode_share_per_%s.csv", g));
}

if (persons.containsColumn(ATTR_REF_MODES)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ final class TripByGroupAnalysis {
}
}

void analyzeModeShare(Table trips, List<String> dists, Function<String, Path> output) {
void analyzeModeShare(Table trips, List<String> dists, List<String> modeOrder, Function<String, Path> output) {

for (Group group : groups) {

Expand All @@ -101,7 +101,7 @@ void analyzeModeShare(Table trips, List<String> dists, Function<String, Path> ou

// Sort by dist_group and mode
Comparator<Row> cmp = Comparator.comparingInt(row -> dists.indexOf(row.getString("dist_group")));
aggr = aggr.sortOn(cmp.thenComparing(row -> row.getString("main_mode")));
aggr = aggr.sortOn(cmp.thenComparingInt(row -> modeOrder.indexOf(row.getString("main_mode"))));

// Norm each group to 1
String norm = group.columns.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,32 +364,62 @@ private void createGroupedTab(Layout layout, String[] args) {

for (String cat : Objects.requireNonNull(categories, "Categories not set")) {

layout.row("category_" + cat, "By Groups").el(Plotly.class, (viz, data) -> {
layout.row("category_" + cat, "By Groups")
.el(Plotly.class, (viz, data) -> {

viz.title = "Mode share";
viz.description = "by " + cat;
viz.layout = tech.tablesaw.plotly.components.Layout.builder()
.xAxis(Axis.builder().title("share").build())
.barMode(tech.tablesaw.plotly.components.Layout.BarMode.STACK)
.build();

Plotly.DataMapping ds = viz.addDataset(data.computeWithPlaceholder(TripAnalysis.class, "mode_share_per_%s.csv", cat))
.pivot(List.of("main_mode", "dist_group", cat), "source", "share")
.aggregate(List.of("main_mode", "source", cat), "share", Plotly.AggrFunc.SUM)
.rename("sim_share", "Sim")
.rename("ref_share", "Ref")
.mapping()
.facetCol(cat)
.name("main_mode")
.x("source")
.y("share");


viz.addTrace(BarTrace.builder(Plotly.OBJ_INPUT, Plotly.INPUT)
.orientation(BarTrace.Orientation.VERTICAL)
.build(), ds);

}).el(Plotly.class, (viz, data) -> {
viz.title = "Modal distance distribution";
viz.description = "by " + cat;
viz.layout = tech.tablesaw.plotly.components.Layout.builder()
.xAxis(Axis.builder().title("Distance group").build())
.yAxis(Axis.builder().title("Share").build())
.barMode(tech.tablesaw.plotly.components.Layout.BarMode.STACK)
.build();

// TODO: should use facet row, but does not work yet
// TODO: hard to see, because too many bars
Plotly.DataMapping ds = viz.addDataset(data.computeWithPlaceholder(TripAnalysis.class, "mode_share_per_%s.csv", cat))
.pivot(List.of("main_mode", "dist_group", cat), "source", "share")
.normalize(List.of("dist_group", "source", cat), "share")
.rename("sim_share", "Sim")
.rename("ref_share", "Ref")
.mapping()
.facetCol(cat)
.name("main_mode")
.x("dist_group")
.y("share");

viz.title = "Mode share";
viz.description = "by " + cat;
viz.layout = tech.tablesaw.plotly.components.Layout.builder()
.xAxis(Axis.builder().title("share").build())
.barMode(tech.tablesaw.plotly.components.Layout.BarMode.STACK)
.build();
viz.multiIndex = Map.of("dist_group", "source");

// TODO: Still in testing
Plotly.DataMapping ds = viz.addDataset(data.computeWithPlaceholder(TripAnalysis.class, "mode_share_per_%s.csv", cat))
.pivot(List.of("main_mode", "dist_group", cat), "source", "share")
.aggregate(List.of("main_mode", "source", cat), "share", Plotly.AggrFunc.SUM)
.rename("sim_share", "Sim")
.rename("ref_share", "Ref")
.mapping()
.facetCol(cat)
.name("main_mode")
.x("share")
.y("source");
viz.addTrace(BarTrace.builder(Plotly.OBJ_INPUT, Plotly.INPUT)
.orientation(BarTrace.Orientation.VERTICAL)
.build(), ds);


viz.addTrace(BarTrace.builder(Plotly.OBJ_INPUT, Plotly.INPUT)
.orientation(BarTrace.Orientation.HORIZONTAL)
.build(), ds);
});
});

}
}
Expand Down

0 comments on commit cab0b80

Please sign in to comment.