The following is the Ruby code and plot for the above example. There is a small difference between the code in the example and the code bellow. If the example is ran, the plot will appear on the screen, bellow, we generate an ‘svg’ image and then include it in this document. In order to generate and image, the R.svg device is used. To generate the plot on the screen, use the R.awt device, as commented on the code.
require 'galaaz'
require 'ggplot'
# load package and data
R.options(scipen: 999) # turn-off scientific notation like 1e+48
R.theme_set(R.theme_bw) # pre-set the bw theme.
midwest = ~:midwest
# midwest <- read.csv("http://goo.gl/G1K41K") # bkup data source
# R.awt # run the awt device if the plot should show on the screen
R.svg # run the svg device if an image should be generated
# Scatterplot
gg = midwest.ggplot(E.aes(x: :area, y: :poptotal)) +
R.geom_point(E.aes(col: :state, size: :popdensity)) +
R.geom_smooth(method: "loess", se: false) +
R.xlim(R.c(0, 0.1)) +
R.ylim(R.c(0, 500000)) +
R.labs(subtitle: "Area Vs Population",
y: "Population",
x: "Area",
title: "Scatterplot",
caption: "Source: midwest")
R.png('midwest.png') # this line is not necessary with the awt device
puts gg
R.dev__off # R.dev__off turns off the device. If using awt, the plot
# window will be closed