对中主对角线上的直方图在R中起作用

时间:2016-05-01 07:57:00

标签: r

我正在尝试使用以下方法在主对角线上用直方图绘制R中的相关矩阵:

object 'panel.hist' not found

但是我得到了

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Paycheck {

    public static void main(String[] args) {

        List<Employee> empList = new ArrayList<Employee>();

        while (true) {
            Scanner input = new Scanner(System.in);
            NumberFormat nf = NumberFormat.getCurrencyInstance();
            System.out.println("Enter the employee name (enter exit to exit): ");
            String empName = input.nextLine();
            // mediaArray[empName];

            if(empName.equals("exit")) {
                break;
            }

            System.out.println("Enter your total sales for the year:  ");
            double totalSales = input.nextDouble();

            Calculations c = new Calculations(totalSales);

            System.out
                    .println("Your Total compensation with your annual sales is:  "
                            + nf.format(c.getCommissionCalc()));

            System.out.println("\r");

            System.out
                    .println("If you were to increase your sales you could earn even more money!");

            System.out.println("\r");
            double i = totalSales + 5000;
            double finish = totalSales * 1.5;

            while (i <= finish) {

                c.totalSales = i;

                System.out
                        .println("If you were to increase your sales commission to "
                                + nf.format(i)
                                + " you could earn: "
                                + nf.format(c.getCommissionCalc()));

                i = i + 5000;
            }
            System.out.println("\r");

            //store employee data into arraylist
            empList.add(new Employee(empName, i));
        }


        for(Employee emp : empList) {
            System.out.println("Employee Name: " + emp.getName() + " Total Sales: " + emp.getSales());
        }
    }
}

class Employee {

    private String name;
    private Double sales;

    public Employee(String empName, double totalSales) {
        this.name = empName;
        this.sales = totalSales;
    }

    public Double getSales() {
        return sales;
    }

    public void setSales(Double sales) {
        this.sales = sales;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

怎么了?

1 个答案:

答案 0 :(得分:2)

您是否已执行代码来定义panel.hist函数?根据配对文档(https://stat.ethz.ch/R-manual/R-devel/library/graphics/html/pairs.html)中的示例:

panel.hist <- function(x, ...)
{
    usr <- par("usr"); on.exit(par(usr))
    par(usr = c(usr[1:2], 0, 1.5) )
    h <- hist(x, plot = FALSE)
    breaks <- h$breaks; nB <- length(breaks)
    y <- h$counts; y <- y/max(y)
    rect(breaks[-nB], 0, breaks[-1], y, col = "cyan", ...)
}

您需要运行此代码以在您的环境中定义panel.hist函数,然后再在pairs()

中引用它