Quantcast
Channel: R.NET
Viewing all articles
Browse latest Browse all 1634

New Post: R.Net doesn't load library("lattice")

$
0
0
Hi, here is the code I am using:
    public void plotGraphR_2D(List<double> x, double[,] y)
    {
        string Rpath = @"C:\Program Files\R\R-3.1.0\bin\x64";

        REngine.SetEnvironmentVariables(Rpath);
        REngine engine = REngine.GetInstance();

        var v1 = engine.CreateNumericVector(x);
        var v2 = engine.CreateNumericMatrix(y);

        if (engine.IsRunning == false)
        {
            engine.Initialize();
        }

        engine.SetSymbol("v1", v1);
        engine.SetSymbol("v2", v2);

        engine.Evaluate("require('ggplot2')");
        engine.Evaluate("library('ggplot2')");
        engine.Evaluate("my_data <- data.frame(v2)");
        engine.Evaluate("colnames(my_data) <- c('Price', 'Quantity')");
        engine.Evaluate("myChart <- ggplot() + geom_line(data = my_data, my_data$Price)"); // THIS DOESN'T WORK
        engine.Evaluate("myChart");
        //engine.Evaluate("plot(my_data$Price)"); // THIS WORKS
    }
My input x is a list while y is a 2 dimensional array. I first convert x to numeric vector and y to data frame, then change column names to the data frame.
I want to plot one of the column of my data frame (my_data$Price) but when using ggplot2 it doesn't work. I don't get any error but I don't see any chart.
If I try using the last line engine.Evaluate("plot(my_data$Price)") so normal plot, it works fine.
Is there any problem with the way I call ggplot2? I have installed the library with RStudio. Anything else I should do to fix the issue?

Thanks.

Viewing all articles
Browse latest Browse all 1634

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>