Julia – The first contact

Today I tried Julia for the first time. I have read about it before, and kept considering whether or not it is worth learning another programming language (see e.g. Should I learn new programming langauge Julia?). And there are many thoughtful comments online on the benefits of Julia compared to other popular high-level programming languages like R, Python, MATLAB, etc. (here, or here), but there are also critical voices (like here). In any case, I decided to have a look at it anyway. My background is in R, so learning Julia should not be too much of a problem. Right?

First, I installed Julia directly from the developers’ website. But, you can also use homebrew to setup Julia. After installation, Julia is immediately accessible through the terminal. 

Screen Shot 2017-08-06 at 11.41.33.png

While I have no problems using the terminal, I still prefer a good IDE. Yeah, I am that kind of person. Previously, I used RStudio and texstudioand am very happy with the additional functionality an IDE provides. I decided to install Juno, which is an extension for the Atom text editor. Simply search and install the uber-junopackage within the Atom editor. It takes a while to load install all the dependencies. Once this is done a new Julia session is initiated. This first start up will also take a few moments.

Hacking 2+2 into the console results in 4. Good, the first test was successful. Now, on to something more adventures. Plotting. I know, this might be too advanced for the first day, but hey, in R plotting belongs to the core functions, and enjoy plotting my data and results. Simply type plot(1:10) in an R console and a plot will appear somewhere.

Screen Shot 2017-08-06 at 11.53.11

Great. So, how to do this in Julia? The Julialang website offers three different options for plotting: Plots, PyPlot, and Gadfly. In order they are the generic way of plotting in Julia, a variant relying on Python's matplotlib, and one that is similar to R's ​ ggplot2 . (I really like ggplot2 a lot, and in combination with cowplot you can make really nice plots, so I guess, in the long run, I will stick with making plots in R).

First, install the Plots package, then call it for the session by using using and then let us plot 2 sets of data each with 10 random numbers:

Pkg.add("Plots")
using Plots
plot(rand(10,2))

And here we go. A quick way to plot:

Screen Shot 2017-08-07 at 17.58.22.pngInterestingly, the created figure is interactive. You can zoom in on data, and pan around. That’s certainly different from the generic R plot.

These first steps have definitely made me interested in exploring Julia more. Less for plotting, but more for using it as my go to agent-based modelling language.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s