Ejemplo n.º 1
0
  public LinePlotTest() {
    super(new BorderLayout());
    setPreferredSize(new Dimension(800, 600));
    setBackground(Color.WHITE);

    // load data from file ----------------------------------------------
    // basemean, log2foldchange
    DataTable nonSigData = new DataTable(Double.class, Double.class);
    DataTable sigData = new DataTable(Double.class, Double.class);
    try (CSVReader reader = new CSVReader(new FileReader("rnaSeqExample.csv"))) {
      String[] nextLine;
      int row = 0;
      while ((nextLine = reader.readNext()) != null) {
        if (row != 0) {
          // needs to have a p-value
          if (nextLine[2].equals("NA")) continue;

          double baseMean = Double.parseDouble(nextLine[1]);
          double log2Change = Double.parseDouble(nextLine[2]);
          if (nextLine[6].equals("NA") || Double.parseDouble(nextLine[6]) > 0.05) {
            nonSigData.add(Math.log10(baseMean), log2Change);
          } else {
            sigData.add(Math.log10(baseMean), log2Change);
          }
        }
        row++;
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    System.out.println("Non-significant: " + nonSigData.getRowCount());
    System.out.println("Significant: " + sigData.getRowCount());

    XYPlot plot = new XYPlot(nonSigData, sigData);

    // set point renderer for data
    PointRenderer points = new DefaultPointRenderer2D();
    points.setShape(new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0));
    points.setColor(NONSIG_COLOR);
    plot.setPointRenderer(nonSigData, points);

    PointRenderer pointsRed = new DefaultPointRenderer2D();
    pointsRed.setShape(new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0));
    pointsRed.setColor(SIG_COLOR);
    plot.setPointRenderer(sigData, pointsRed);

    // Display on screen
    add(new InteractivePanel(plot), BorderLayout.CENTER);
  }
Ejemplo n.º 2
0
  /**
   * Takes a matrix of values and creates a new data source that stores the values in (x, y, value)
   * format.
   *
   * @param data Original data source with values in each cell.
   * @return New data source with (x, y, value) columns
   */
  @SuppressWarnings("unchecked")
  public static DataSource createRasterData(DataSource data) {
    if (data == null) {
      throw new NullPointerException("Cannot convert null data source.");
    }

    DataTable coordsValueData = new DataTable(Double.class, Double.class, Double.class);

    // Generate pixel data with (x, y, value)
    Statistics stats = data.getStatistics();
    double min = stats.get(Statistics.MIN);
    double max = stats.get(Statistics.MAX);
    double range = max - min;
    int i = 0;
    for (Comparable<?> cell : data) {
      int x = i % data.getColumnCount();
      int y = -i / data.getColumnCount();
      double v = Double.NaN;
      if (cell instanceof Number) {
        Number numericCell = (Number) cell;
        v = (numericCell.doubleValue() - min) / range;
      }
      coordsValueData.add((double) x, (double) y, v);
      i++;
    }
    return coordsValueData;
  }
Ejemplo n.º 3
0
  @SuppressWarnings("unchecked")
  public SimplePiePlot() {
    // Create data
    DataTable data = new DataTable(Integer.class);
    for (int i = 0; i < SAMPLE_COUNT; i++) {
      int val = random.nextInt(8) + 2;
      data.add((random.nextDouble() <= 0.15) ? -val : val);
    }

    // Create new pie plot
    PiePlot plot = new PiePlot(data);

    // Format plot
    plot.getTitle().setText(getDescription());
    // Change relative size of pie
    plot.setRadius(0.9);
    // Display a legend
    plot.setLegendVisible(true);
    // Add some margin to the plot area
    plot.setInsets(new Insets2D.Double(20.0, 40.0, 40.0, 40.0));

    PieSliceRenderer pointRenderer = (PieSliceRenderer) plot.getPointRenderer(data);
    // Change relative size of inner region
    pointRenderer.setInnerRadius(0.4);
    // Change the width of gaps between segments
    pointRenderer.setGap(0.2);
    // Change the colors
    LinearGradient colors = new LinearGradient(COLOR1, COLOR2);
    pointRenderer.setColor(colors);
    // Show labels
    pointRenderer.setValueVisible(true);
    pointRenderer.setValueColor(Color.WHITE);
    pointRenderer.setValueFont(Font.decode(null).deriveFont(Font.BOLD));

    // Add plot to Swing component
    add(new InteractivePanel(plot), BorderLayout.CENTER);
  }