versioninfo() #= To Install RCall: using Pkg Pkg.add("RCall") =# using RCall X = randn(3,2) b = reshape([2.0, 3.0], 2,1) y = X * b + randn(3,1) # Note that X and y are julia variables. @rput sends y and X to R with the same names @rput y @rput X # Fit a model in R R"mod <- lm(y ~ X-1)" R"summary(mod)" # If you want to retrieve a variable from R, look at this example R"z <- y * 3" @rget z z # In this example, we really need to use reval R_lm(some_str_expr) = reval(rparse("lm(" * some_str_expr * ")")) R_summary = R"summary" R_mod = R_lm("y ~ X-1") R_summary(R_mod) # Finally, plotting. Note that if you don't set ylab and xlab, you'll get a very messy plot... R_plot = R"plot" R_plot(x=rand(100),y=rand(100),pch=20,cex=2,fg="grey",bty="n",ylab="",xlab="") R"plot(X[,1],y)" # Now, you can call R_plot in julia quite like you call plot in R R"plot(rnorm(2000))" R_plot = R"plot"; R_plot(x=randn(2000),ylab="") R""" library(ggplot2) str(iris) """ # http://motw.mods.jp/R/ggplot_facet.html R""" p <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) p + geom_point(colour="gray50", size=3) + geom_point(aes(colour=Species)) """ # http://motw.mods.jp/R/ggplot_geom_histogram.html R""" p <- ggplot(iris, aes(x=Sepal.Length)) p + geom_histogram(aes(colour=Species),bins=30) """ R""" p + geom_histogram(aes(fill=Species),bins=30) """ R""" str(diamonds) """ # http://motw.mods.jp/R/ggplot_facet.html R""" p <- ggplot(diamonds, aes(x=carat, y=price)) p + geom_point(aes(colour=clarity)) + facet_grid(cut ~ color, margins=TRUE) """ # https://mrunadon.github.io/ggplot2/ R""" g3<-ggplot(iris,aes(x=Sepal.Length)) #確率密度曲線を描いていきたいので、y軸の宣言は不要です。確率密度がy軸になるので。 g3<-g3+geom_density(aes(fill=Species),size=0.5,alpha=0.5) #geom_density()を使います g3<-g3+xlim(3,10) #x軸は3から10の範囲としましょう。 g3 """ # https://mrunadon.github.io/ggplot2/ R""" g3<-ggplot(iris,aes(x=Sepal.Length)) g3<-g3+geom_density(aes(fill=Species),size=0.5,alpha=0.5) g3<-g3+xlim(3,10) g3 """ R"hoge <- 3" @rget hoge moge = Float64(pi) @rput moge R"moge" poge = [ 1 2 3; 4 5 6; 7 8 9; ] @rput poge R"poge" pogecopy = deepcopy(poge) R"poge <- 2*poge" @rget poge poge pogecopy