Last active
August 29, 2015 14:12
-
-
Save nzbart/f48df61f68c4935b337e to your computer and use it in GitHub Desktop.
This sample plots a simple chart to a PNG file using the R statistical program and R.Net. It requires the R.NET.Community NuGet package to be installed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using RDotNet; | |
/* | |
d:/temp/plot.r: | |
suppressPackageStartupMessages(library(ggplot2)) | |
library(ggplot2) | |
p <- qplot(Sepal.Length, Petal.Length, data = iris, color = Species) | |
png(filename=fileName, width=500, height=500) | |
plot(p) | |
dev.off() | |
*/ | |
class Program | |
{ | |
static void Main() | |
{ | |
REngine.SetEnvironmentVariables(); // <-- May be omitted; the next line would call it. | |
using (REngine engine = REngine.GetInstance()) | |
{ | |
const string fileName = @"D:\temp\image.png"; | |
engine.SetSymbol("fileName", engine.CreateCharacterVector(new []{ fileName })); | |
engine.Evaluate("source('d:/temp/plot.r')"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment