Skip to content

Commit d6b9175

Browse files
authored
Merge pull request #109 from rwoldford/master
The version to go with the release 1.3.1 on github
2 parents 28f95b0 + 9af36fe commit d6b9175

7 files changed

+263
-8
lines changed

R/_pkgdown.yml

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ reference:
235235

236236

237237

238+
238239
- title: Loon display layers
239240
desc: Loon plots have multiple display layers
240241
contents:

R/demo/00Index

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
loon an introductory example
2-
l_glyphs demonstrate glyph types
3-
l_glyph_sizes size mapping to various glyph types
42
l_map layer a map from the map R package
53
l_layers demonstrate layer types
4+
l_layout custom layout widgets
65
l_linking linking examples
6+
l_linkPrimitiveGlyphs custom linking, link the primitive glyphs
7+
l_glyphs demonstrate glyph types
8+
l_glyph_sizes size mapping to various glyph types
9+
l_make_glyphs anything R can draw can be a glyph
10+
periodic_table explore the periodicity in the table using custom glyphs
711
l_polygons_sp layer polygons with class sp as defined in the sp R package
12+
l_widgets custom layout
813
l_power scatterplot and two scales that control the power transformation for each axis
914
l_timeseries seasonal trend decomposition stl
1015
l_regression layer fit, confidence, and prediction intervals
@@ -14,12 +19,9 @@ l_selectToActive two scatterplots; in one a regression is fit to the points t
1419
l_us_and_them gapminder data made famous by Hans Rosling; fertility, life expectancy, and income
1520
l_us_and_them_slider show the life expectancy vs. fertility data for the year selected on a slider
1621
l_us_and_them_choropleth life expectancy on a world map and linked with a scatterplot
17-
l_linkPrimitiveGlyphs custom linking, link the primitive glyphs
1822
l_add_regressions interactively add regression lines of a particular order to selected points
1923
l_knn interactively highlight k nearest points in some subspace
2024
l_ng_images_frey_LLE navigation graph for the frey image data using LLE for dimensionality reduction
2125
l_ng_images_frey_isomap navigation graph for the frey image data using isomap for dimensionality reduction
2226
l_ng_images_faces navigation graph with olivetti faces data
2327
l_ng_dimred compare results from various dimensionality reduction methods using navigation graphs
24-
l_layout custom layout widgets
25-
l_widgets custom layout

R/demo/l_make_glyphs.R

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
2+
# Produce any statistical glyph from any drawing function(on png)
3+
# Add these glyphs as the point symbols for the loon scatterplot.
4+
#
5+
# Here we look at Italian growing areas corresponding to the
6+
# olive oil data.
7+
# The location of each area is a point in the loon plot
8+
# We introduce a new glyph for each point/growing area based on a
9+
# scatterplot of the fatty acid pair (linoleic, arachidic)
10+
# for all olive oils in that growing area.
11+
# Then a map of Italy is layered on the scatterplot.
12+
13+
if(requireNamespace("maps", quietly = TRUE)) {
14+
local({
15+
16+
p <- with(oliveLocations,
17+
l_plot(x = long, y = lat,
18+
xlabel = "longitude", ylabel = "latitude",
19+
showGuides = TRUE, color = "darkolivegreen4",
20+
itemLabel = Area, showItemLabels = TRUE,
21+
title = "Olive oil growing areas")
22+
)
23+
24+
readline("Hit <Return> to construct the statistical images (9 in total)")
25+
#
26+
# Now we construct statistical glyphs for each area.
27+
# First split the olive data into a list by Area
28+
# in the order of the Area from the scatterplot
29+
#
30+
oliveByArea <- lapply(oliveLocations$Area,
31+
FUN = function(area) {
32+
subset(olive,
33+
Area == area)})
34+
35+
# Want the scatterplot glyphs to all be on the
36+
# same range and to have the Area superimposed
37+
# on top.
38+
# We'll use base graphics to construct the glyphs
39+
# Will be producing a scatterplot of two fatty acids
40+
# for each growing area
41+
xlim <- extendrange(olive[,"linoleic"], f = .25)
42+
ylim <- extendrange(olive[,"arachidic"], f = .25)
43+
xlim10 <- extendrange(olive[,"linoleic"], f = .10)
44+
ylim10 <- extendrange(olive[,"arachidic"], f = .10)
45+
pointcol <- adjustcolor("steelblue", 0.5)
46+
textcol <- "steelblue"
47+
#
48+
# Now construct the statistical images
49+
scatterplot_images <-
50+
l_make_glyphs(
51+
oliveByArea, # data
52+
width = 300, height = 300, # image size
53+
draw_fun = function(area) { # draw function for each Area
54+
# Following line included *only* for demo
55+
devAskNewPage(ask = FALSE)
56+
# get rid of borders for the png device
57+
par(mai = rep(0,4),
58+
mar = rep(0,4),
59+
oma = rep(0,4))
60+
61+
# Draw the plot we want
62+
# Just a scatterplot of two of the fatty
63+
# acids
64+
plot(area$linoleic, area$arachidic,
65+
xlim = xlim, ylim = ylim,
66+
ann = FALSE, xaxt = "n", yaxt = "n", bty = "n",
67+
pch=19, cex = 2, col = pointcol)
68+
# Add text of Area name
69+
text(mean(xlim), min(ylim10), # Bottom of plot
70+
paste(area$Area[1]),
71+
cex = 3.5, col = textcol)
72+
}
73+
)
74+
75+
readline("Hit <Return> to get images for viewer")
76+
# Look at the images
77+
l_imageviewer(scatterplot_images)
78+
79+
readline("Hit <Return> to assign statistical images as point glyphs")
80+
81+
# Create the glyphs from the images for the l_plot
82+
glyphs <- l_glyph_add_image(p,
83+
scatterplot_images,
84+
# A meaningful label for this glyph
85+
label = "plot(linoleic, arachidic)"
86+
)
87+
# Change the plot glyphs to these image glyphs
88+
p["glyph"] <- glyphs
89+
90+
readline("Hit <Return> to finish plot by layering a map of Italy")
91+
92+
# Now layer a map of Italy from the maps package
93+
l_layer(p,
94+
maps::map('italy', fill = FALSE, plot = FALSE),
95+
label = "Italy",
96+
color = "cornsilk",
97+
index = "end")
98+
# Scale the plot to the all layers
99+
l_scaleto_world(p)
100+
101+
}) # End local
102+
}

R/demo/periodic_table.R

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
2+
# This uses l_make_glyphs to build standard periodic table labels
3+
# for glyphs of the elements data from loon.data package.
4+
#
5+
6+
if(requireNamespace("loon.data", quietly = TRUE)) {
7+
local({
8+
data("elements", package = "loon.data")
9+
10+
# A draw function for each element
11+
draw_element_box <- function(symbol,
12+
name, number,
13+
mass_number,
14+
mass, col) {
15+
if (missing(col)) col <- "white"
16+
oldPar <- par(bg = col, mar = rep(1, 4))
17+
#
18+
# Following line included *only* for demo
19+
devAskNewPage(ask = FALSE)
20+
21+
plot(NA, xlim = c(0,1), ylim = c(0, 1), axes=FALSE, ann = FALSE)
22+
text(0.5, 0.6, labels = symbol, cex = 18)
23+
text(0.15, 1, labels = number, cex = 6, adj= c(0.5,1))
24+
text(0.5, 0.25, labels = name, cex = 6)
25+
text(0.5, 0.11, labels = mass_number, cex = 3)
26+
text(0.5, 0.01, labels = mass, cex = 3)
27+
box()
28+
29+
par(oldPar)
30+
}
31+
32+
# Get the categories
33+
colIDs <- paste(elements$Category, elements$Subcategory)
34+
# Get a loon palette function
35+
colFn <- color_loon()
36+
# Get colors identified with categories
37+
tableCols <- colFn(colIDs)
38+
#
39+
# A function to an element box image for each element.
40+
41+
make_element_boxes <- function(elements,
42+
cols,
43+
width = 500,
44+
height = 500) {
45+
if (missing(cols)) cols <- rep("white", nrow(elements))
46+
listOfElements <- lapply(1:nrow(elements),
47+
FUN = function(i) {
48+
list(vals = elements[i,],
49+
col = cols[i])
50+
})
51+
# glyphs created here
52+
l_make_glyphs(listOfElements,
53+
draw_fun = function(element){
54+
x <- element$vals
55+
col <- element$col
56+
draw_element_box(symbol = x$Symbol,
57+
name = x$Name,
58+
number = x$Number,
59+
mass_number = x$Mass_number,
60+
mass = x$Mass,
61+
col = col)
62+
},
63+
width = width,
64+
height = height)
65+
}
66+
67+
# Construct the glyphs
68+
boxGlyphs <- make_element_boxes(elements, cols = tableCols)
69+
70+
readline("Hit <Return> to scroll through the elements")
71+
# Look at the images
72+
l_imageviewer(boxGlyphs)
73+
74+
readline("Hit <Return> to lay them out in the periodic table.")
75+
76+
# Get a couple of plots
77+
periodicTable <- l_plot(x = elements$x, y = elements$y,
78+
xlabel = "", ylabel = "",
79+
title = "Periodic Table of the Elements",
80+
linkingGroup = "elements",
81+
color = tableCols)
82+
83+
# Add the images as possible glyphs
84+
85+
bg <- l_glyph_add_image(periodicTable,
86+
images = boxGlyphs,
87+
label = "Symbol box")
88+
89+
# Set this to be the glyph
90+
periodicTable['glyph'] <- bg
91+
92+
message("Enlarge the window so that all elements can be seen. \n")
93+
94+
readline(
95+
"Hit <Return> to construct a plot of each element's Density versus its Mass.")
96+
#
97+
# Get a second plot that shows the periodicity
98+
#
99+
# First some itemlabels
100+
elementLabels <- with(elements,
101+
paste(" ", Number, Symbol, "\n",
102+
" ", Name, "\n",
103+
" ", Mass
104+
)
105+
)
106+
107+
periodicPlot <- l_plot(x = elements$Mass, y = elements$Density,
108+
xlabel = "Mass", ylabel = "Density",
109+
itemLabel = elementLabels,
110+
showItemLabels = TRUE,
111+
linkingGroup = "elements",
112+
color = tableCols)
113+
114+
115+
bg2 <- l_glyph_add_image(periodicPlot,
116+
images = boxGlyphs,
117+
label = "Symbol box")
118+
119+
120+
readline(
121+
"Hit <Return> to show the noble gases by their 'Symbol Box' glyph")
122+
123+
nobleGases <- elements$Subcategory == "Noble gas"
124+
periodicPlot["glyph"][nobleGases] <- "glyph0"
125+
readline(
126+
"Hit <Return> to show the reactive nonmetals by their 'Symbol Box' glyph")
127+
reactiveNonMetals <- elements$Subcategory == "Reactive nonmetal"
128+
periodicPlot["glyph"][reactiveNonMetals] <- "glyph0"
129+
130+
readline("Hit <Return> to focus on the noble gases and the reactive nonmetals")
131+
periodicPlot["active"] <- nobleGases | reactiveNonMetals
132+
l_scaleto_active(periodicPlot)
133+
periodicPlot["active"] <- TRUE
134+
135+
readline("Hit <Return> to return plot to closed circles and scale.")
136+
periodicPlot["glyph"] <- "ccircle"
137+
l_scaleto_world(periodicPlot)
138+
139+
message(paste0("Suggestions: \n",
140+
" - Brush/Select in either plot to explore the periodicity of the elements. \n",
141+
" - On the table brushing whole rows or whole columns is interesting. \n",
142+
" - Try selecting by colour and setting the glyph to the symbol boxes. \n",
143+
" - So activating only selected colours and panning and zooming in the Mass/Density plot. \n",
144+
" - Activate only selected colours and then try panning and zooming in the Mass/Density plot. \n"))
145+
146+
message()
147+
148+
149+
}) # End local
150+
}

docs/articles/introduction.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/teaching-example-smoothing.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/pkgdown.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ articles:
55
introduction: introduction.html
66
savingLoonPlots: savingLoonPlots.html
77
teaching-example-smoothing: teaching-example-smoothing.html
8-
last_built: 2020-06-13T14:30Z
8+
last_built: 2020-06-15T18:27Z
99

0 commit comments

Comments
 (0)