<?xml version="1.0" encoding="UTF-8"?>
<!-- Written by .github/scripts/build_feed.py. Do not edit by hand. -->
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>sedzinfo · R tutorials</title>
    <link>https://sedzinfo.github.io/vignettes/</link>
    <atom:link href="https://sedzinfo.github.io/vignettes/feed.xml" rel="self" type="application/rss+xml"/>
    <description>Tutorials in R with the code on every page: psychometrics, adaptive testing, scale validation, statistics, machine learning and data visualization with real data.</description>
    <language>en</language>
    <lastBuildDate>Wed, 02 Dec 2026 17:16:25 +0200</lastBuildDate>
    <item>
      <title>Where Everything Is Today: The Solar System in 3D</title>
      <link>https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SOLAR_SYSTEM.html</link>
      <guid isPermaLink="true">https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SOLAR_SYSTEM.html</guid>
      <pubDate>Wed, 02 Dec 2026 17:16:25 +0200</pubDate>
      <category>R</category>
      <category>Illustrations in R</category>
      <description>The Sun, the planets, thousands of asteroids and objects beyond Neptune, comets, three visitors from other stars and the five spacecraft that are leaving the solar system, each placed where it is today from NASA JPL’s Horizons system and Small-Body Database, in 3D charts made with plotly: how far light has to travel, what lies beyond Neptune, where the spacecraft are going, and which comets will come back.</description>
      <content:encoded><![CDATA[<p><em>The Sun, the planets, thousands of asteroids and objects beyond Neptune, comets, three visitors from other stars and the five spacecraft that are leaving the solar system, each placed where it is today from NASA JPL’s Horizons system and Small-Body Database, in 3D charts made with plotly: how far light has to travel, what lies beyond Neptune, where the spacecraft are going, and which comets will come back.</em></p>
<p><img src="https://sedzinfo.github.io/vignettes/illustration/social-card.png" alt="Illustrations in R" width="1200" height="630"></p>
<section id="what-is-this" class="level2">
<h2 class="anchored" data-anchor-id="what-is-this">What is this?</h2>
<p>Everything in the solar system moves, each body on its own orbit around the Sun. This story places the planets, the asteroids, the comets and the spacecraft that are leaving the solar system where they are today, and asks five questions:</p>
<ol type="1">
<li><strong>Where is everything today?</strong></li>
<li><strong>How far is far?</strong></li>
<li><strong>What lies beyond Neptune?</strong></li>
<li><strong>Where are the spacecraft going?</strong></li>
<li><strong>Which comets come back, and which never will?</strong></li>
</ol>
<p>The data are NASA’s, from its Jet Propulsion Laboratory (JPL): the orbits of the planets, the dwarf planets and the comets, and the paths of the spacecraft, from its <strong>Horizons</strong> system, which computes them from the JPL ephemerides (<a href="https://doi.org/10.3847/1538-3881/abd414">Park et al.&nbsp;2021</a>); and the orbits of thousands of asteroids and of every known object beyond Neptune from its <strong>Small-Body Database</strong>. They are downloaded when the page is rendered. The charts can be turned with the mouse and zoomed, and every body shows its name when the pointer is over it. The page follows <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SATELLITES.html">The Crowded Sky</a>, which does the same for the satellites around the Earth.</p>
<p><strong>The words of this page:</strong></p>
<ul>
<li>an <strong>AU</strong> (astronomical unit) is about the average distance from the Earth to the Sun: 149,597,870.7 km. Light covers it in 8 minutes and 19 seconds;</li>
<li>an <strong>orbit</strong> is the path of a body around the Sun: an ellipse, a stretched circle with the Sun at one of its two foci. <strong>Perihelion</strong> is its point closest to the Sun, <strong>aphelion</strong> its point furthest away. An orbit can also be open (a <strong>hyperbola</strong>): then the body passes the Sun once and leaves for ever;</li>
<li>the <strong>ecliptic</strong> is the plane of the Earth’s orbit. The charts are drawn on it, seen from its north side, where the planets go round the Sun anticlockwise; most orbits lie close to it;</li>
<li><strong>asteroids</strong> are small rocky bodies. Most of them orbit in the <strong>main belt</strong>, between Mars and Jupiter; <strong>Jupiter’s Trojans</strong> share Jupiter’s orbit, in two crowds, one ahead of the planet and one behind it;</li>
<li>the <strong>Kuiper belt</strong> is a ring of icy bodies beyond Neptune. <strong>Dwarf planets</strong>, such as Pluto and Eris, are round like planets but share their orbits with many other bodies;</li>
<li><strong>comets</strong> are lumps of ice and dust on stretched orbits; near the Sun, their ice turns to gas and they grow a tail;</li>
<li>the <strong>heliosphere</strong> is the bubble that the wind of the Sun blows into the gas between the stars; its edge, the <strong>heliopause</strong>, is where interstellar space begins.</li>
</ul>
<hr>
</section>
<section id="packages" class="level2">
<h2 class="anchored" data-anchor-id="packages">Packages</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1"><pre><code class="language-r"># install.packages(c("plotly","jsonlite"))
library(plotly)</code></pre></div></div>
</details>
</div>
</section>
<section id="the-data" class="level2">
<h2 class="anchored" data-anchor-id="the-data">The data</h2>
<p>An orbit is given by six numbers: its size, its shape, its tilt to the ecliptic, how it is turned around the Sun and within its own plane, and where the body is on it at a given moment. Horizons gives these numbers for each planet, dwarf planet and comet as they are today (its <strong>osculating</strong> orbit: the orbit that the body would keep if the planets stopped pulling on it), and the page draws the orbit and places the body from them. For the spacecraft, Horizons gives the path itself, from launch to today. The Small-Body Database gives the orbits of the asteroids and of the objects beyond Neptune at an earlier moment, and Kepler’s equation moves each one along its orbit to today.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2"><pre><code class="language-r"># the copies of the answers kept on this computer: an answer of Horizons is kept under the date of
# the page and downloaded at most once a day; the orbits of the small bodies change little and are
# downloaded again after 30 days. A service that does not answer is asked again, up to three more
# times, 10 seconds apart; if it still does not answer, an older copy is used if there is one
kept&lt;-tools::R_user_dir("illustration",which="cache")
dir.create(kept,recursive=TRUE,showWarnings=FALSE)
download_kept&lt;-function(url,name,hours=Inf,tries=4) {
  file&lt;-file.path(kept,name)
  if(file.exists(file)&amp;&amp;difftime(Sys.time(),file.mtime(file),units="hours")&lt;hours)
    return(file)
  temporary&lt;-tempfile()
  for(k in seq_len(tries)) {
    done&lt;-tryCatch(download.file(url,temporary,quiet=TRUE,mode="wb")==0,
                   error=function(e) FALSE,warning=function(w) FALSE)
    if(done) {
      file.copy(temporary,file,overwrite=TRUE)
      # at most one question a second to the services
      Sys.sleep(1)
      return(file)
    }
    if(k&lt;tries)
      Sys.sleep(10)
  }
  if(file.exists(file))
    return(file)
  stop("Could not download ",url)
}
# a name as a part of a file name: "Comet Hale–Bopp" becomes "comet_hale_bopp"
slug&lt;-function(x) {
  result&lt;-gsub("^_|_$","",gsub("[^a-z0-9]+","_",tolower(iconv(x,to="ASCII//TRANSLIT"))))
  return(result)
}
# a question to Horizons: the orbit (ELEMENTS) or the positions (VECTORS) of a body, seen from the
# center of the Sun, on the plane of the ecliptic, in AU and days
horizons&lt;-function(command,type,start,stop,step) {
  values&lt;-c(COMMAND=command,OBJ_DATA="NO",MAKE_EPHEM="YES",EPHEM_TYPE=type,CENTER="500@10",
            START_TIME=start,STOP_TIME=stop,STEP_SIZE=step,REF_PLANE="ECLIPTIC",
            OUT_UNITS="AU-D",CSV_FORMAT="YES",VEC_TABLE="1")
  query&lt;-paste0(names(values),"=",vapply(paste0("'",values,"'"),URLencode,"",reserved=TRUE),
                collapse="&amp;")
  result&lt;-paste0("https://ssd.jpl.nasa.gov/api/horizons.api?format=json&amp;",query)
  return(result)
}
# the table of an answer of Horizons, between its lines $$SOE and $$EOE, with its column names
horizons_table&lt;-function(file) {
  text&lt;-jsonlite::fromJSON(file)$result
  lines&lt;-strsplit(text,"\n")[[1]]
  first&lt;-which(lines=="$$SOE")
  last&lt;-which(lines=="$$EOE")
  if(!length(first))
    stop("Horizons gave no table: ",substr(text,1,300))
  header&lt;-trimws(strsplit(lines[first-2],",")[[1]])
  rows&lt;-read.csv(text=paste(lines[(first+1):(last-1)],collapse="\n"),header=FALSE,
                 strip.white=TRUE)[,seq_along(header)]
  names(rows)&lt;-header
  result&lt;-rows[,header!=""]
  return(result)
}
# a question to the Small-Body Database: the orbits of a class of small bodies, with a condition
sbdb&lt;-function(class,condition=NULL) {
  query&lt;-c(fields="full_name,a,e,i,om,w,ma,epoch,H",`sb-class`=class)
  if(!is.null(condition))
    query&lt;-c(query,`sb-cdata`=condition)
  url&lt;-paste0("https://ssd-api.jpl.nasa.gov/sbdb_query.api?",
              paste0(names(query),"=",vapply(query,URLencode,"",reserved=TRUE),collapse="&amp;"))
  answer&lt;-jsonlite::fromJSON(download_kept(url,paste0("sbdb_",tolower(class),".json"),
                                           hours=24*30))
  result&lt;-as.data.frame(answer$data,stringsAsFactors=FALSE)
  names(result)&lt;-answer$fields
  for(v in c("a","e","i","om","w","ma","epoch","H"))
    result[[v]]&lt;-as.numeric(result[[v]])
  result$name&lt;-trimws(result$full_name)
  # a body whose orbit is too poorly known to place it on it (no mean anomaly) is left out
  result&lt;-result[complete.cases(result[,c("a","e","i","om","w","ma","epoch")]),]
  return(result)
}</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3"><pre><code class="language-r"># the day of the page, at 0:00 UTC
today&lt;-as.Date(format(Sys.time(),"%Y-%m-%d",tz="UTC"))
today_jd&lt;-as.numeric(today)+2440587.5   # its Julian date
d2r&lt;-pi/180
# a point of an orbit, in AU from the Sun: x towards the March equinox, y 90° further along the
# ecliptic, z towards the north of the ecliptic. q: the distance at perihelion, e: the shape (0 a
# circle, below 1 an ellipse, above 1 a hyperbola), the angles in radians, and nu the angle from
# the perihelion, seen from the Sun (the true anomaly)
orbit_point&lt;-function(q,e,tilt,node,perihelion,nu) {
  r&lt;-q*(1+e)/(1+e*cos(nu))
  u&lt;-perihelion+nu
  result&lt;-data.frame(x=r*(cos(node)*cos(u)-sin(node)*sin(u)*cos(tilt)),
                     y=r*(sin(node)*cos(u)+cos(node)*sin(u)*cos(tilt)),
                     z=r*sin(u)*sin(tilt))
  return(result)
}
# the line of an orbit from Horizons' numbers, in 360 steps; an orbit that reaches further than
# `reach` AU from the Sun, as an open orbit always does, is drawn only where it is closer
orbit_line&lt;-function(b,reach=Inf) {
  far&lt;-if(b$EC&lt;1) b$QR*(1+b$EC)/(1-b$EC) else Inf
  limit&lt;-if(far&lt;=reach) pi else acos((b$QR*(1+b$EC)/reach-1)/b$EC)
  result&lt;-orbit_point(b$QR,b$EC,b$IN*d2r,b$OM*d2r,b$W*d2r,seq(-limit,limit,length.out=361))
  return(result)
}
# where small bodies are today, from the orbits of the Small-Body Database at an earlier moment
# (epoch): each moves on along its orbit by its mean motion, from Gauss's constant (the Sun's
# gravity: radians a day on an orbit of 1 AU), and Kepler's equation gives the place
gauss&lt;-0.01720209895
place_today&lt;-function(s) {
  motion&lt;-gauss/s$a^1.5
  anomaly&lt;-(s$ma*d2r+motion*(today_jd-s$epoch))%%(2*pi)
  # Kepler's equation, solved by Newton's method, starting from pi for very stretched orbits
  eccentric&lt;-ifelse(s$e&gt;0.8,pi,anomaly)
  for(step in 1:50)
    eccentric&lt;-eccentric-(eccentric-s$e*sin(eccentric)-anomaly)/(1-s$e*cos(eccentric))
  nu&lt;-2*atan2(sqrt(1+s$e)*sin(eccentric/2),sqrt(1-s$e)*cos(eccentric/2))
  result&lt;-cbind(s,orbit_point(s$a*(1-s$e),s$e,s$i*d2r,s$om*d2r,s$w*d2r,nu))
  result$r&lt;-sqrt(result$x^2+result$y^2+result$z^2)
  return(result)
}</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4"><pre><code class="language-r"># the planets, the dwarf planets, three comets and the three visitors from other stars that are
# known, with the names that Horizons knows them by
bodies&lt;-data.frame(
  name=c("Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune",
         "Ceres","Pluto","Haumea","Makemake","Eris",
         "Halley's comet","Comet 67P","Comet Hale–Bopp",
         "1I/ʻOumuamua","2I/Borisov","3I/ATLAS"),
  command=c("199","299","399","499","599","699","799","899",
            "1;","999","136108;","136472;","136199;",
            "DES=1P;CAP","DES=67P;CAP","C/1995 O1",
            "A/2017 U1","C/2019 Q4","C/2025 N1"),
  kind=c(rep("planet",8),rep("dwarf",5),rep("comet",3),rep("visitor",3)))
# their orbits as they are today: the shape (EC), the distance at perihelion (QR), the tilt (IN),
# the turns (OM, W), the date of perihelion (Tp, a Julian date), the angle from the perihelion
# today (TA) and the size (A, half the longest width; negative for an open orbit)
elements&lt;-lapply(seq_len(nrow(bodies)),function(k)
  horizons_table(download_kept(horizons(bodies$command[k],"ELEMENTS",format(today),
                                        format(today+1),"1 d"),
                               paste0("horizons_",slug(bodies$name[k]),"_",today,".json")))[1,])
bodies&lt;-cbind(bodies,do.call(rbind,elements)[,c("EC","QR","IN","OM","W","Tp","TA","A")])
bodies&lt;-cbind(bodies,with(bodies,orbit_point(QR,EC,IN*d2r,OM*d2r,W*d2r,TA*d2r)))
bodies$r&lt;-sqrt(bodies$x^2+bodies$y^2+bodies$z^2)
rownames(bodies)&lt;-bodies$name
# the asteroids of the main belt whose absolute magnitude H is below 12, the brightest and so
# mostly the largest; Jupiter's Trojans with H below 13; and every object known beyond Neptune
main_belt&lt;-place_today(sbdb("MBA",'{"AND":["H|LT|12"]}'))
trojans&lt;-place_today(sbdb("TJN",'{"AND":["H|LT|13"]}'))
kuiper&lt;-place_today(sbdb("TNO"))
# the five spacecraft that are leaving the solar system: their paths from a few days after launch to
# today, in 600 steps
probes&lt;-data.frame(name=c("Pioneer 10","Pioneer 11","Voyager 2","Voyager 1","New Horizons"),
                   command=c("-23","-24","-32","-31","-98"),
                   start=as.Date(c("1972-03-05","1973-04-08","1977-08-23","1977-09-08",
                                   "2006-01-21")))
paths&lt;-lapply(seq_len(nrow(probes)),function(k) {
  file&lt;-download_kept(horizons(probes$command[k],"VECTORS",format(probes$start[k]),format(today),
                               "600"),
                      paste0("horizons_path_",slug(probes$name[k]),"_",today,".json"))
  path&lt;-horizons_table(file)
  data.frame(date=as.Date(path$JDTDB-2440587.5),x=path$X,y=path$Y,z=path$Z)
})
names(paths)&lt;-probes$name
for(k in names(paths))
  paths[[k]]$r&lt;-sqrt(paths[[k]]$x^2+paths[[k]]$y^2+paths[[k]]$z^2)
probes$r&lt;-vapply(paths,function(p) p$r[nrow(p)],0)</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5"><pre><code class="language-r">dark_gray&lt;-"#6b6b6b" # also the color of the notes
orbit_gray&lt;-"#b3b3b3"
planet_gray&lt;-"#8f8f8f"  # the bars of the planets
ink&lt;-"#191919"
sun_yellow&lt;-"#f2a600"
# the colors of the groups, told apart also by color-blind readers (each set checked)
blue&lt;-"#257de0"
orange&lt;-"#f47230"
green&lt;-"#00b894"
probe_colour&lt;-c(`Pioneer 10`=blue,`Pioneer 11`=orange,`Voyager 2`=green,`Voyager 1`="#6a4ce2",
                `New Horizons`="#ee7fac")
# the source of a chart, as a note under it, and the common layout; note_shift moves the note down
# by a number of pixels, which stays the same however tall the plot is
chart&lt;-function(p,title,source,y_title="",x_title="",y_axis=list(),x_axis=list(),
                annotations=list(),margin=list(t=70,b=90),note_y=-0.16,note_shift=0,...) {
  note&lt;-list(text=paste("Source:",source),xref="paper",yref="paper",x=0,y=note_y,xanchor="left",
             yanchor="top",yshift=note_shift,align="left",showarrow=FALSE,
             font=list(size=11,color=dark_gray))
  result&lt;-layout(p,
                 title=list(text=title,x=0.02,xanchor="left",y=0.97,yanchor="top"),
                 margin=margin,
                 annotations=c(annotations,list(note)),
                 ...)
  if(nchar(paste0(y_title,x_title))&gt;0||length(c(y_axis,x_axis))&gt;0)
    result&lt;-layout(result,yaxis=modifyList(list(title=y_title),y_axis),
                   xaxis=modifyList(list(title=x_title),x_axis))
  result&lt;-config(result,displaylogo=FALSE)
  return(result)
}
legend_top&lt;-list(orientation="h",x=0,y=1.02,yanchor="bottom",itemsizing="constant")
horizons_source&lt;-"NASA JPL Horizons: osculating orbits of today, Sun-centred, on the ecliptic."
sbdb_source&lt;-"NASA JPL Small-Body Database, moved along their orbits to today."
# short labels of numbers and dates
number&lt;-function(x) {
  result&lt;-format(round(x),big.mark=",",trim=TRUE,scientific=FALSE)
  return(result)
}
one&lt;-function(x) {
  result&lt;-format(round(x,1),nsmall=1,trim=TRUE)
  return(result)
}
date_words&lt;-function(x) {
  result&lt;-paste(as.integer(format(x,"%d")),month.name[as.integer(format(x,"%m"))],format(x,"%Y"))
  return(result)
}
month_words&lt;-function(x) {
  result&lt;-paste(month.name[as.integer(format(x,"%m"))],format(x,"%Y"))
  return(result)
}
jd_date&lt;-function(jd) {
  result&lt;-as.Date(jd-2440587.5)
  return(result)
}
when&lt;-date_words(today)
# 3D charts. Distances in hundredths of an AU, as whole numbers: plotly for R writes any other
# number with 17 digits (8.49 as 8.4900000000000002). The axes are hidden, all three as long as each
# other, out to r AU from the Sun, and the view is from above the ecliptic, a little to one side
au&lt;-function(x) {
  result&lt;-round(100*x)
  return(result)
}
eye&lt;-c(x=0.45,y=-1.05,z=0.75)
space_scene&lt;-function(r) {
  axis&lt;-list(range=c(-100*r,100*r),visible=FALSE)
  result&lt;-list(xaxis=axis,yaxis=axis,zaxis=axis,aspectmode="cube",dragmode="turntable",
               camera=list(eye=as.list(eye)))
  return(result)
}
# the directions to the right and upwards on the screen, as the charts are first seen from the eye
forward&lt;-(-eye)/sqrt(sum(eye^2))
screen_right&lt;-c(forward[["y"]],-forward[["x"]],0)/sqrt(forward[["x"]]^2+forward[["y"]]^2)
screen_up&lt;-c(screen_right[2]*forward[["z"]],-screen_right[1]*forward[["z"]],
             screen_right[1]*forward[["y"]]-screen_right[2]*forward[["x"]])
# the side of each body on which its name is written: away from the Sun as the chart is first
# seen; and two bodies close together on the screen (less than a quarter of the view apart) with
# their names on the same side get one name to the left and one to the right, the closest pairs
# first, each body once. view: the distance from the Sun in view, in AU
label_sides&lt;-function(b,view) {
  position&lt;-as.matrix(b[,c("x","y","z")])/view
  across&lt;-as.vector(position%*%screen_right)
  up&lt;-as.vector(position%*%screen_up)
  vertical&lt;-ifelse(abs(up)&lt;0.4*abs(across),"middle",ifelse(up&gt;=0,"top","bottom"))
  side&lt;-ifelse(across&gt;=0,"right","left")
  pairs&lt;-which(upper.tri(diag(length(side))),arr.ind=TRUE)
  apart&lt;-sqrt((across[pairs[,1]]-across[pairs[,2]])^2+(up[pairs[,1]]-up[pairs[,2]])^2)
  moved&lt;-rep(FALSE,length(side))
  for(k in order(apart)) {
    i&lt;-pairs[k,1]
    j&lt;-pairs[k,2]
    if(apart[k]&lt;0.25&amp;&amp;!moved[i]&amp;&amp;!moved[j]&amp;&amp;vertical[i]==vertical[j]&amp;&amp;side[i]==side[j]) {
      side[c(i,j)]&lt;-if(across[i]&lt;across[j]) c("left","right") else c("right","left")
      moved[c(i,j)]&lt;-TRUE
    }
  }
  # a body near the left or right edge gets its name on the side towards the Sun, and above it if
  # it was beside it, so that the name is not cut off on a narrow screen
  edge&lt;-abs(across)&gt;0.6
  vertical[edge&amp;vertical=="middle"]&lt;-"top"
  side[edge]&lt;-ifelse(across[edge]&gt;0,"left","right")
  result&lt;-paste(vertical,side)
  return(result)
}
# the orbits of several bodies as one line, with a gap after each orbit
orbit_lines&lt;-function(b,reach=Inf) {
  lines&lt;-lapply(seq_len(nrow(b)),function(k) rbind(orbit_line(b[k,],reach),NA))
  result&lt;-do.call(rbind,lines)
  result&lt;-data.frame(x=au(result$x),y=au(result$y),z=au(result$z))
  return(result)
}
# the Sun, and bodies as points with their names next to them; view: as in label_sides, others:
# bodies of the same chart added apart, whose names they must not cover, and group: the legend
# entry of their orbits, which then turn on and off with them
add_sun&lt;-function(p,legend=TRUE) {
  result&lt;-add_trace(p,x=0,y=0,z=0,type="scatter3d",mode="markers",name="Sun",showlegend=legend,
                    marker=list(color=sun_yellow,size=8,line=list(color=ink,width=1)),
                    hovertemplate="&lt;b&gt;Sun&lt;/b&gt;&lt;extra&gt;&lt;/extra&gt;",inherit=FALSE)
  return(result)
}
add_bodies&lt;-function(p,b,name,view,colour=ink,size=4,others=NULL,group=NULL) {
  sides&lt;-label_sides(rbind(b[,c("x","y","z")],others[,c("x","y","z")]),view)[seq_len(nrow(b))]
  result&lt;-add_trace(p,data=data.frame(x=au(b$x),y=au(b$y),z=au(b$z),label=b$name,
                                      hover=paste0("&lt;b&gt;",b$name,"&lt;/b&gt;&lt;br&gt;",one(b$r),
                                                   " AU from the Sun")),
                    x=~x,y=~y,z=~z,type="scatter3d",mode="markers+text",name=name,text=~label,
                    textposition=sides,textfont=list(size=11,color=ink),
                    customdata=~hover,hovertemplate="%{customdata}&lt;extra&gt;&lt;/extra&gt;",
                    marker=list(color=colour,size=size,line=list(color="#ffffff",width=1)),
                    legendgroup=group,inherit=FALSE)
  return(result)
}
# a 3D chart is built once and its second copy of every number ("attrs") dropped. zooms: buttons
# that zoom in and out, a label and a distance from the Sun in AU for each. At every zoom a name
# is written only next to a body more than 6% of that distance from the Sun, so that the names of
# the bodies close to the Sun do not pile up on it; the chart opens at the zoom of its scene
finish_3d&lt;-function(p,zooms=NULL) {
  result&lt;-plotly_build(p)
  result$x$attrs&lt;-NULL
  if(is.null(zooms))
    return(result)
  named&lt;-which(vapply(result$x$data,function(t) grepl("text",paste(t$mode,collapse="")),TRUE))
  labels&lt;-lapply(result$x$data[named],function(t) t$text)
  far&lt;-lapply(result$x$data[named],function(t) sqrt(t$x^2+t$y^2+t$z^2)/100)
  zooms&lt;-c(open=result$x$layout$scene$xaxis$range[2]/100,zooms)
  shown&lt;-lapply(zooms,function(view) Map(function(l,r) ifelse(r&gt;0.06*view,l,""),labels,far))
  for(k in seq_along(named))
    result$x$data[[named[k]]]$text&lt;-shown$open[[k]]
  buttons&lt;-lapply(names(zooms)[-1],function(z) {
    range&lt;-c(-100,100)*zooms[[z]]
    list(label=z,method="update",
         args=list(list(text=unname(shown[[z]])),
                   list(scene.xaxis.range=range,scene.yaxis.range=range,scene.zaxis.range=range),
                   as.list(named-1)))
  })
  result$x$layout$updatemenus&lt;-list(list(type="buttons",direction="right",x=0,y=0,xanchor="left",
                                         yanchor="top",showactive=FALSE,buttons=buttons))
  return(result)
}
planets&lt;-bodies[bodies$kind=="planet",]</code></pre></div></div>
</details>
</div>
<hr>
</section>
<section id="where-is-everything-today" class="level2">
<h2 class="anchored" data-anchor-id="where-is-everything-today">1. Where is everything today?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6"><pre><code class="language-r">earth&lt;-bodies["Earth",]
jupiter&lt;-bodies["Jupiter",]
# the angle of each Trojan ahead of Jupiter (+) or behind it (−), along the ecliptic, in degrees
longitude&lt;-function(x,y) {
  result&lt;-atan2(y,x)/d2r
  return(result)
}
trojans$ahead&lt;-((longitude(trojans$x,trojans$y)-longitude(jupiter$x,jupiter$y)+180)%%360)-180
leading&lt;-trojans$ahead&gt;0
belt_range&lt;-quantile(main_belt$a,c(0.05,0.95))
# the time that each planet takes to go round the Sun, in years: by Kepler's third law, the size
# of its orbit (half its longest width, in AU) to the power 1.5
planets$years&lt;-planets$A^1.5</code></pre></div></div>
</details>
</div>
<p><strong>Eight planets in nearly one plane, and two crowds of asteroids.</strong> On 2 December 2026, the Earth was 0.986 AU from the Sun. Between Mars and Jupiter, the 2,016 brightest asteroids of the main belt orbit between 2.4 and 3.2 AU from the Sun (nine out of ten of them). Further out, Jupiter’s 1,558 brightest Trojans travel along its orbit in two crowds: 927 about 61° ahead of the planet, and 631 about 62° behind it, at the two points where the pulls of the Sun and of Jupiter hold them.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7"><pre><code class="language-r">p&lt;-plot_ly() %&gt;%
  add_trace(data=orbit_lines(planets),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
            name="Orbits of the planets",line=list(color=orbit_gray,width=2),hoverinfo="skip")
for(g in list(list(data=main_belt,colour=blue,name="Main belt"),
              list(data=trojans,colour=orange,name="Jupiter's Trojans"))) {
  points&lt;-data.frame(x=au(g$data$x),y=au(g$data$y),z=au(g$data$z),
                     hover=paste0("&lt;b&gt;",g$data$name,"&lt;/b&gt;&lt;br&gt;",one(g$data$r)," AU from the Sun"))
  p&lt;-add_trace(p,data=points,x=~x,y=~y,z=~z,type="scatter3d",mode="markers",
               name=paste0(g$name,": ",number(nrow(g$data))),customdata=~hover,
               hovertemplate="%{customdata}&lt;extra&gt;&lt;/extra&gt;",
               marker=list(color=g$colour,size=1.6,line=list(width=0)),inherit=FALSE)
}
p %&gt;%
  add_sun() %&gt;%
  add_bodies(planets,"Planets",6) %&gt;%
  chart(paste("The solar system on",when),paste(horizons_source,sbdb_source),
        margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,legend=legend_top,
        scene=space_scene(6)) %&gt;%
  finish_3d(c(`Inner planets`=1.8,`Out to Jupiter`=6,`Out to Neptune`=32))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SOLAR_SYSTEM.html">Interactive chart: The solar system on 2 December 2026</a></p>
</div>
</div>
<p>Each gray ring is the orbit of a planet, and each planet stands where it is today. <strong>Inner planets</strong> zooms in on Mercury, Venus, the Earth and Mars; <strong>Out to Neptune</strong> shows the four giants, and how far apart they are: the main belt and everything inside it shrink to a small disc around the Sun. Seen from this side, they all go round the Sun anticlockwise: the Earth in a year, Jupiter in 11.9 years and Neptune in 165.</p>
<hr>
</section>
<section id="how-far-is-far" class="level2">
<h2 class="anchored" data-anchor-id="how-far-is-far">2. How far is far?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8"><pre><code class="language-r">light_seconds&lt;-499.004784             # seconds that light takes to cover 1 AU
light_day&lt;-86400/light_seconds         # AU that light covers in a day
# Voyager 1 and the Earth every day from 2026 to 2028: when is Voyager 1 one light-day away from us?
window&lt;-c("2026-01-01","2028-12-31")
daily&lt;-lapply(c(`Voyager 1`="-31",Earth="399"),function(command)
  horizons_table(download_kept(horizons(command,"VECTORS",window[1],window[2],"1 d"),
                               paste0("horizons_daily_",gsub("[^0-9]","",command),"_",
                                      paste(window,collapse="_"),".json"))))
apart&lt;-sqrt((daily$`Voyager 1`$X-daily$Earth$X)^2+(daily$`Voyager 1`$Y-daily$Earth$Y)^2+
              (daily$`Voyager 1`$Z-daily$Earth$Z)^2)
days&lt;-jd_date(daily$Earth$JDTDB)
first_day&lt;-days[which(apart&gt;light_day)[1]]
for_good&lt;-days[max(which(apart&lt;=light_day))+1]
voyager1&lt;-paths[["Voyager 1"]][nrow(paths[["Voyager 1"]]),]
voyager1_earth&lt;-sqrt((voyager1$x-earth$x)^2+(voyager1$y-earth$y)^2+(voyager1$z-earth$z)^2)
# the sentence about it: before, on or after the first day, and whether it comes back within a
# light-day while the Earth goes round the Sun, now towards Voyager 1 and now away from it
light_day_words&lt;-paste0("one light-day (",one(light_day)," AU)")
voyager_day&lt;-paste(if(today&lt;first_day) "It will be" else "It was",light_day_words,
                   "away from the Earth for the first time on",date_words(first_day))
voyager_day&lt;-if(for_good&gt;first_day)
  paste0(voyager_day,", and as the Earth goes round the Sun, now towards it and now away, ",
         if(today&lt;for_good) "it will come" else "it came"," back within a light-day until ",
         date_words(for_good-1),".") else
  paste0(voyager_day,", and it will never again be closer.")
# light time from the Sun, in hours, to the planets, Pluto, Eris and the spacecraft
chosen&lt;-bodies[bodies$kind=="planet"|bodies$name%in%c("Pluto","Eris"),]
far&lt;-rbind(data.frame(name=chosen$name,r=chosen$r,colour=planet_gray),
           data.frame(name=probes$name,r=probes$r,colour=probe_colour[probes$name]))
far$hours&lt;-far$r*light_seconds/3600
far&lt;-far[order(far$r),]
light_words&lt;-function(hours) {
  result&lt;-ifelse(hours&lt;1,paste(one(60*hours),"min"),paste(one(hours),"h"))
  return(result)
}
proxima&lt;-4.24*365.25*24   # light-hours to the nearest star, Proxima Centauri, 4.24 light-years</code></pre></div></div>
</details>
</div>
<p><strong>Light takes 8.3 minutes to reach us from the Sun, and almost a day to reach Voyager 1.</strong> Light from the Sun reaches Neptune in 4.1 hours and Eris, 95.4 AU away today, in 13.2 hours. Voyager 1, the furthest spacecraft, is 172.5 AU from the Sun: 23.9 light-hours, or 25.8 billion km. Today it is 173.3 AU from the Earth, so its radio signals take 24.0 hours to reach us. It was one light-day (173.1 AU) away from the Earth for the first time on 19 November 2026, and it will never again be closer.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9"><pre><code class="language-r">far$label&lt;-light_words(far$hours)
plot_ly(far,x=~hours,y=~name,type="bar",orientation="h",marker=list(color=~I(colour)),
        text=~label,textposition="outside",cliponaxis=FALSE,customdata=~one(r),
        hovertemplate="&lt;b&gt;%{y}&lt;/b&gt;: %{customdata} AU, %{text}&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  chart(paste("How long light takes to get there from the Sun,",when),
        "NASA JPL Horizons: the distance of each from the Sun today.",
        x_title="Light time from the Sun (a logarithmic scale)",
        x_axis=list(type="log",tickvals=c(1/60,10/60,1,10,24),
                    ticktext=c("1 min","10 min","1 h","10 h","1 day"),range=log10(c(0.02,60))),
        y_axis=list(categoryorder="array",categoryarray=far$name,title=""),
        margin=list(t=60,b=110,l=110),note_y=-0.2)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SOLAR_SYSTEM.html">Interactive chart: How long light takes to get there from the Sun, 2 December 2026</a></p>
</div>
</div>
<p>Gray bars are planets and dwarf planets, colored bars spacecraft, in the colors of their paths in question 4. From one mark of the scale to the next, the time grows tenfold. Voyager 1 is 5.8 times as far from the Sun as Neptune, after 49 years of travel. Yet the nearest star, Proxima Centauri, 4.24 light-years away, is about 1,550 times as far as Voyager 1.</p>
<hr>
</section>
<section id="what-lies-beyond-neptune" class="level2">
<h2 class="anchored" data-anchor-id="what-lies-beyond-neptune">3. What lies beyond Neptune?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10"><pre><code class="language-r">neptune&lt;-bodies["Neptune",]
pluto&lt;-bodies["Pluto",]
eris&lt;-bodies["Eris",]
# where an orbit goes round the Sun 2 times for every 3 of Neptune's (3:2), 1 for every 2 (2:1) or
# 2 for every 5 (5:2): by Kepler's third law, at the size of Neptune's orbit times the ratio of the
# times to the power 2/3
resonance&lt;-c(`3:2`=neptune$A*(3/2)^(2/3),`2:1`=neptune$A*2^(2/3),`5:2`=neptune$A*(5/2)^(2/3))
near_32&lt;-abs(kuiper$a-resonance[["3:2"]])&lt;0.4
classical&lt;-kuiper$a&gt;42&amp;kuiper$a&lt;resonance[["2:1"]]
# orbits larger than 50 AU, and those of them that are nearly round: their furthest point less than
# 1.5 times as far from the Sun as their closest (a shape, e, below 0.2)
beyond_50&lt;-kuiper$a&gt;50
round_50&lt;-beyond_50&amp;kuiper$e&lt;0.2
pluto_perihelion&lt;-jd_date(pluto$Tp)
inside_neptune&lt;-pluto$QR&lt;neptune$QR</code></pre></div></div>
</details>
</div>
<p><strong>Thousands of icy bodies, gathered where Neptune’s rhythm lets them be.</strong> JPL’s database knows the orbits of 8,444 objects beyond Neptune’s. 773 of them, 9%, have orbits within 0.4 AU of 39.4 AU in size, where a body goes round the Sun twice while Neptune goes round three times (the <strong>3:2 resonance</strong>). Pluto is one of them, and so they are called <strong>plutinos</strong>: its orbit comes closer to the Sun than Neptune’s (its last perihelion was in 1989), but the rhythm keeps the two from ever meeting. That many bodies would share Pluto’s rhythm, and gather at the 2:1 resonance (47.7 AU) too, was predicted when only a few were known (<a href="https://doi.org/10.1086/117532">Malhotra 1995</a>). 3,741 more, the <strong>classical belt</strong>, have orbits between 42 AU and the 2:1 resonance. Further out the crowd changes: 27% of the orbits are larger than 50 AU, but only 87 of these 2,266 are nearly round. The rest are long and stretched, most of them thought to belong to bodies that Neptune threw outward (the <strong>scattered disc</strong>): the belt of nearly round orbits seems to end near 50 AU (<a href="https://doi.org/10.1086/320917">Trujillo and Brown 2001</a>). Today Pluto is 35.7 AU from the Sun, and Eris, the most massive dwarf planet known, 95.4 AU.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11"><pre><code class="language-r">dwarfs&lt;-bodies[bodies$kind=="dwarf"&amp;bodies$name!="Ceres",]
points&lt;-data.frame(x=au(kuiper$x),y=au(kuiper$y),z=au(kuiper$z),
                   hover=paste0("&lt;b&gt;",kuiper$name,"&lt;/b&gt;&lt;br&gt;",one(kuiper$r)," AU from the Sun"))
plot_ly() %&gt;%
  add_trace(data=orbit_lines(planets),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
            name="Orbits of the planets",line=list(color=orbit_gray,width=2),hoverinfo="skip") %&gt;%
  add_trace(data=orbit_lines(dwarfs),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
            name="Orbits of the dwarf planets",hoverinfo="skip",
            line=list(color=dark_gray,width=2,dash="dash")) %&gt;%
  add_trace(data=points,x=~x,y=~y,z=~z,type="scatter3d",mode="markers",
            name=paste0("Beyond Neptune: ",number(nrow(kuiper))),customdata=~hover,
            hovertemplate="%{customdata}&lt;extra&gt;&lt;/extra&gt;",
            marker=list(color=green,size=1.6,line=list(width=0)),inherit=FALSE) %&gt;%
  add_sun() %&gt;%
  add_bodies(bodies[c("Jupiter","Saturn","Uranus","Neptune",dwarfs$name),],
             "Planets and dwarf planets",55) %&gt;%
  chart(paste("Beyond Neptune on",when),paste(horizons_source,sbdb_source),
        margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,legend=legend_top,
        scene=space_scene(55)) %&gt;%
  finish_3d(c(`The Kuiper belt`=55,`Out to Eris`=100))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SOLAR_SYSTEM.html">Interactive chart: Beyond Neptune on 2 December 2026</a></p>
</div>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12"><pre><code class="language-r">breaks&lt;-seq(30,80,by=0.5)
counts&lt;-table(cut(kuiper$a,breaks,right=FALSE))
bars&lt;-data.frame(a=breaks[-length(breaks)]+0.25,objects=as.vector(counts))
marks&lt;-lapply(names(resonance),function(k)
  list(type="line",x0=resonance[[k]],x1=resonance[[k]],y0=0,y1=1,yref="paper",
       line=list(color=dark_gray,width=1.5,dash="dot")))
labels&lt;-lapply(names(resonance),function(k)
  list(x=resonance[[k]],y=1,yref="paper",text=k,showarrow=FALSE,
       xanchor="left",yanchor="top",xshift=4,font=list(size=12,color=dark_gray)))
plot_ly(bars,x=~a,y=~objects,type="bar",marker=list(color=green),
        hovertemplate="%{x:.1f} AU: %{y} objects&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  chart("Objects beyond Neptune by the size of their orbit, and Neptune's rhythms",
        "NASA JPL Small-Body Database.",
        "Objects (every half AU)","Half the longest width of the orbit, AU",
        x_axis=list(range=c(30,80),showgrid=FALSE),shapes=marks,annotations=labels,bargap=0.05,
        margin=list(t=70,b=100),note_y=-0.25)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SOLAR_SYSTEM.html">Interactive chart: Objects beyond Neptune by the size of their orbit, and Neptune&#x27;s rhythms</a></p>
</div>
</div>
<p>Each bar counts the orbits of one size, measured by half their longest width, and the dotted lines mark Neptune’s rhythms. The tall spike at 39.4 AU is the plutinos; the broad hump from 42 AU is the classical belt, which ends at the 2:1 resonance; and further out, a smaller spike sits at 55.4 AU, where a body goes round the Sun twice while Neptune goes round five times (the 5:2 resonance).</p>
<hr>
</section>
<section id="where-are-the-spacecraft-going" class="level2">
<h2 class="anchored" data-anchor-id="where-are-the-spacecraft-going">4. Where are the spacecraft going?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13"><pre><code class="language-r"># the distance of a spacecraft from the Sun on a date, from its path
distance_on&lt;-function(name,date) {
  result&lt;-approx(paths[[name]]$date,paths[[name]]$r,xout=as.Date(date))$y
  return(result)
}
# how fast each moves away from the Sun now, in AU a year: over the last year of its path
speed&lt;-vapply(probes$name,function(k) {
  p&lt;-paths[[k]]
  back&lt;-which.min(abs(p$date-(today-365)))
  (p$r[nrow(p)]-p$r[back])/as.numeric(p$date[nrow(p)]-p$date[back])*365.25
},0)
events&lt;-data.frame(name=c("Voyager 1","Voyager 2","Pioneer 11","Pioneer 10"),
                   date=as.Date(c("2012-08-25","2018-11-15","1995-11-24","2003-01-23")),
                   what=c("left the heliosphere","left the heliosphere","last signal",
                          "last signal"))
events$r&lt;-mapply(distance_on,events$name,events$date)
furthest&lt;-probes[order(-probes$r),]</code></pre></div></div>
</details>
</div>
<p><strong>Five spacecraft are on paths that will take them out of the solar system for good</strong> (<a href="https://science.nasa.gov/mission/pioneer-11/">NASA 2025b</a>). Voyager 1 is the furthest, 172.5 AU from the Sun, and moves away by 3.6 AU a year; then come Voyager 2 (144.6 AU), Pioneer 10 (142.4 AU), Pioneer 11 (118.3 AU) and New Horizons, launched in 2006 to Pluto, at 66.2 AU. Voyager 1 left the heliosphere for interstellar space in August 2012, 121.6 AU from the Sun (<a href="https://doi.org/10.1126/science.1241681">Gurnett et al.&nbsp;2013</a>), and Voyager 2 in November 2018, at about 119 AU (<a href="https://doi.org/10.1038/s41550-019-0928-3">Stone et al.&nbsp;2019</a>). The two Pioneers are silent: Pioneer 11 sent its last data in November 1995, 44 AU from the Sun, and Pioneer 10 its last signal in January 2003, at 82 AU (<a href="https://science.nasa.gov/mission/pioneer-10/">NASA 2025a</a>, <a href="https://science.nasa.gov/mission/pioneer-11/">2025b</a>); their places today are computed from the paths they were on.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14"><pre><code class="language-r">outer&lt;-planets[planets$name%in%c("Jupiter","Saturn","Uranus","Neptune"),]
p&lt;-plot_ly() %&gt;%
  add_trace(data=orbit_lines(outer),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
            name="Orbits of Jupiter to Neptune",line=list(color=orbit_gray,width=2),
            hoverinfo="skip")
# where each spacecraft is today, with its name on the side away from the Sun
ends&lt;-do.call(rbind,lapply(probes$name,function(k) cbind(name=k,paths[[k]][nrow(paths[[k]]),])))
ends$side&lt;-label_sides(ends,180)
for(k in probes$name) {
  path&lt;-paths[[k]]
  line&lt;-data.frame(x=au(path$x),y=au(path$y),z=au(path$z),
                   hover=paste0("&lt;b&gt;",k,"&lt;/b&gt;&lt;br&gt;",date_words(path$date),": ",one(path$r),
                                " AU from the Sun"))
  p&lt;-add_trace(p,data=line,x=~x,y=~y,z=~z,type="scatter3d",mode="lines",name=k,legendgroup=k,
               line=list(color=probe_colour[[k]],width=4),customdata=~hover,
               hovertemplate="%{customdata}&lt;extra&gt;&lt;/extra&gt;",inherit=FALSE)
  p&lt;-add_trace(p,data=line[nrow(line),],x=~x,y=~y,z=~z,type="scatter3d",mode="markers+text",
               text=k,textposition=ends$side[ends$name==k],textfont=list(size=11,color=ink),
               legendgroup=k,showlegend=FALSE,marker=list(color=probe_colour[[k]],size=5),
               customdata=~hover,hovertemplate="%{customdata}&lt;extra&gt;&lt;/extra&gt;",inherit=FALSE)
}
p %&gt;%
  add_sun(legend=FALSE) %&gt;%
  chart(paste("Five spacecraft leaving the solar system, from launch to",when),
        "NASA JPL Horizons: the path of each spacecraft, Sun-centred, on the ecliptic.",
        margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,legend=legend_top,
        scene=space_scene(180)) %&gt;%
  finish_3d(c(`Today`=180,`The planets`=35))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SOLAR_SYSTEM.html">Interactive chart: Five spacecraft leaving the solar system, from launch to 2 December 2026</a></p>
</div>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15"><pre><code class="language-r">p&lt;-plot_ly()
for(k in probes$name)
  p&lt;-add_trace(p,data=paths[[k]],x=~date,y=~round(r,1),type="scatter",mode="lines",name=k,
               line=list(color=probe_colour[[k]],width=2),
               hovertemplate=paste0(k,": %{y} AU&lt;extra&gt;&lt;/extra&gt;"))
p&lt;-add_trace(p,data=events,x=~date,y=~round(r,1),type="scatter",mode="markers",
             name="Left the heliosphere, or last signal",text=~paste(name,what),
             marker=list(color=ink,size=8,symbol="circle-open",line=list(width=2)),
             hovertemplate="%{text}: %{y} AU&lt;extra&gt;&lt;/extra&gt;")
# the names at the ends of the lines; two that would be closer than 7% of the height are moved
# apart, each by half of what is missing
end_labels&lt;-probes[order(probes$r),c("name","r")]
gap&lt;-0.07*max(end_labels$r)
for(k in seq_len(nrow(end_labels))[-1]) {
  missing&lt;-gap-(end_labels$r[k]-end_labels$r[k-1])
  if(missing&gt;0)
    end_labels$r[c(k-1,k)]&lt;-end_labels$r[c(k-1,k)]+c(-1,1)*missing/2
}
labels&lt;-lapply(seq_len(nrow(end_labels)),function(k)
  list(x=today,y=end_labels$r[k],text=end_labels$name[k],showarrow=FALSE,xanchor="left",
       xshift=6,font=list(size=11,color=ink)))
chart(p,"Distance from the Sun","NASA JPL Horizons: the path of each spacecraft.",
      "AU from the Sun","",x_axis=list(showgrid=FALSE,range=c(as.Date("1971-01-01"),today+365)),
      annotations=labels,hovermode="x unified",legend=legend_top,
      margin=list(t=110,b=80,r=100),note_y=-0.12)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SOLAR_SYSTEM.html">Interactive chart: Distance from the Sun</a></p>
</div>
</div>
<p>Each line bends upward where its spacecraft passed close to a planet, whose gravity threw it outward faster: Jupiter for all five, then Saturn for Pioneer 11 and the two Voyagers, and Uranus and Neptune for Voyager 2. Since their last pass, they have been coasting along almost straight lines.</p>
<hr>
</section>
<section id="which-comets-come-back-and-which-never-will" class="level2">
<h2 class="anchored" data-anchor-id="which-comets-come-back-and-which-never-will">5. Which comets come back, and which never will?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16"><pre><code class="language-r">halley&lt;-bodies["Halley's comet",]
# the time that a body takes to go round the Sun, in years: Kepler's third law
period_years&lt;-function(b) {
  result&lt;-b$A^1.5
  return(result)
}
# the orbit of today puts Halley's next perihelion on a date; its path in Horizons, which takes in
# the pulls of the planets, gives the real one (hour by hour, within 15 days of that date), and the
# days of its last perihelion and of its furthest point (a period and half a period earlier)
halley_path&lt;-function(middle,days,step) {
  window&lt;-format(middle+c(-days,days))
  path&lt;-horizons_table(download_kept(horizons("DES=1P;CAP","VECTORS",window[1],window[2],step),
                                     paste0("horizons_halley_",paste(window,collapse="_"),
                                            ".json")))
  result&lt;-data.frame(time=as.POSIXct((path$JDTDB-2440587.5)*86400,origin="1970-01-01",tz="UTC"),
                     r=sqrt(path$X^2+path$Y^2+path$Z^2))
  return(result)
}
orbit_next&lt;-jd_date(halley$Tp)
period_days&lt;-round(period_years(halley)*365.25)
around&lt;-halley_path(orbit_next,15,"1 h")
halley_next&lt;-as.Date(around$time[which.min(around$r)])
around&lt;-halley_path(orbit_next-period_days,60,"1 d")
halley_last&lt;-as.Date(around$time[which.min(around$r)])
around&lt;-halley_path(orbit_next-round(period_days/2),90,"1 d")
halley_aphelion&lt;-as.Date(around$time[which.max(around$r)])
halley_far&lt;-max(around$r)
comet67p&lt;-bodies["Comet 67P",]
hale_bopp&lt;-bodies["Comet Hale–Bopp",]
visitors&lt;-bodies[bodies$kind=="visitor",]
# the speed of a visitor far from the Sun, in km/s: from the size of its open orbit (A, negative),
# the speed of the Earth on its orbit times the square root of 1 over the size
visitors$speed&lt;-29.7847/sqrt(-visitors$A)
visitors$perihelion&lt;-jd_date(visitors$Tp)
atlas&lt;-visitors["3I/ATLAS",]</code></pre></div></div>
</details>
</div>
<p><strong>Comets on closed orbits come back; the three visitors from other stars never will.</strong> Halley’s comet is 35.0 AU from the Sun. It passed the far end of its orbit on 9 December 2023, 35.1 AU out, and is on its way back: it will be closest to the Sun on 28 July 2061, 75 years after its last visit, in February 1986. Comet 67P, which ESA’s Rosetta spacecraft visited, goes round in 6.4 years, and Hale–Bopp, the bright comet of 1997, now 51.4 AU out, in about 2,400. The three visitors from other stars, ʻOumuamua (found in October 2017), Borisov (August 2019) and 3I/ATLAS (July 2025), came on open orbits (<a href="https://doi.org/10.1038/nature25020">Meech et al.&nbsp;2017</a>; <a href="https://doi.org/10.1038/s41550-019-0931-8">Guzik et al.&nbsp;2020</a>; <a href="https://minorplanetcenter.net/mpec/K25/K25N12.html">MPC 2025</a>). Far from the Sun, before its gravity sped them up and after it slowed them down again, they move at 26, 32 and 58 km/s: too fast for the Sun to hold them. 3I/ATLAS was closest to the Sun on 29 October 2025 and is already 13.9 AU away.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17"><pre><code class="language-r">comets&lt;-bodies[bodies$kind=="comet",]
reach&lt;-60
p&lt;-plot_ly() %&gt;%
  add_trace(data=orbit_lines(planets),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
            name="Orbits of the planets",line=list(color=orbit_gray,width=2),hoverinfo="skip") %&gt;%
  add_trace(data=orbit_lines(comets,reach),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
            name="Comets of the Sun",legendgroup="comets",showlegend=FALSE,
            line=list(color=blue,width=3),hoverinfo="skip") %&gt;%
  add_trace(data=orbit_lines(visitors,reach),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
            name="Visitors from other stars",legendgroup="visitors",showlegend=FALSE,
            line=list(color=orange,width=3),hoverinfo="skip")
p %&gt;%
  add_sun(legend=FALSE) %&gt;%
  add_bodies(comets,"Comets of the Sun",reach,colour=blue,others=visitors,group="comets") %&gt;%
  add_bodies(visitors,"Visitors from other stars",reach,colour=orange,others=comets,
             group="visitors") %&gt;%
  chart(paste("Comets and visitors from other stars on",when),
        paste(horizons_source,"Orbits drawn out to",reach,"AU from the Sun."),
        margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,legend=legend_top,
        scene=space_scene(reach)) %&gt;%
  finish_3d(c(`Out to Jupiter`=6,`Out to Neptune`=32,`Out to 60 AU`=reach))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SOLAR_SYSTEM.html">Interactive chart: Comets and visitors from other stars on 2 December 2026</a></p>
</div>
</div>
<p>The orbits are drawn out to 60 AU: Hale–Bopp’s goes on to about 362 AU, and the visitors’ paths go on for ever. A comet on a closed orbit comes back; a visitor passes once, and leaves.</p>
<hr>
</section>
<section id="so-what-does-it-mean" class="level2">
<h2 class="anchored" data-anchor-id="so-what-does-it-mean">So, what does it mean?</h2>
<p><strong>The solar system is mostly empty, and it reaches much further than the planets.</strong></p>
<ol type="1">
<li><strong>The planets</strong> orbit in nearly one plane, with the main belt of asteroids between Mars and Jupiter and Jupiter’s 1,558 Trojans in two crowds on its orbit.</li>
<li><strong>Distances</strong>: light from the Sun reaches the Earth in 8.3 minutes, Neptune in 4.1 hours, and Voyager 1 in 23.9 hours.</li>
<li><strong>Beyond Neptune</strong>, 8,444 known bodies gather where Neptune’s rhythm protects them, and thin out beyond 50 AU.</li>
<li><strong>Five spacecraft</strong> are leaving; the two Voyagers have already crossed into interstellar space.</li>
<li><strong>Comets</strong> on closed orbits come back, Halley’s in 2061; the three visitors from other stars pass once.</li>
</ol>
<p><strong>What this does not show.</strong> The orbits are those of today: the planets pull on each other, and on every small body, so each orbit changes slowly, and a comet’s next perihelion can come a few days earlier or later than its orbit of today says: for Halley’s comet, the orbit of today says 1 August 2061, its path, which takes in the pulls of the planets, 28 July 2061. The Sun, the planets and the dots of the small bodies are not drawn to scale: at the scale of the orbits even the Sun would be smaller than a pixel. The asteroids shown are only the brightest of the main belt and of the Trojans: hundreds of thousands more are known. The objects beyond Neptune are those that JPL’s database knows, which is where telescopes have looked, not all that are there. And the solar system goes on far beyond the furthest of them: the Oort cloud, from which long-period comets are thought to come, has never been seen.</p>
<hr>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<ul>
<li>Gurnett, D.A., Kurth, W.S., Burlaga, L.F. and Ness, N.F. (2013), <a href="https://doi.org/10.1126/science.1241681">In situ observations of interstellar plasma with Voyager 1</a>, <em>Science</em> 341, 1489–1492.</li>
<li>Guzik, P. and others (2020), <a href="https://doi.org/10.1038/s41550-019-0931-8">Initial characterization of interstellar comet 2I/Borisov</a>, <em>Nature Astronomy</em> 4, 53–57.</li>
<li>Malhotra, R. (1995), <a href="https://doi.org/10.1086/117532">The origin of Pluto’s orbit: implications for the solar system beyond Neptune</a>, <em>The Astronomical Journal</em> 110, 420.</li>
<li>Meech, K.J. and others (2017), <a href="https://doi.org/10.1038/nature25020">A brief visit from a red and extremely elongated interstellar asteroid</a>, <em>Nature</em> 552, 378–381.</li>
<li>Minor Planet Center (2025), <a href="https://minorplanetcenter.net/mpec/K25/K25N12.html">MPEC 2025-N12: 3I/ATLAS = C/2025 N1 (ATLAS)</a>: discovered on 1 July 2025, on a hyperbolic orbit.</li>
<li>NASA (2025a), <a href="https://science.nasa.gov/mission/pioneer-10/">Pioneer 10</a>: its last signal, 23 January 2003.</li>
<li>NASA (2025b), <a href="https://science.nasa.gov/mission/pioneer-11/">Pioneer 11</a>: its last data, 24 November 1995, and the five spacecraft leaving the solar system.</li>
<li>NASA JPL, <a href="https://ssd.jpl.nasa.gov/horizons/">Horizons System</a> and its <a href="https://ssd-api.jpl.nasa.gov/doc/horizons.html">API</a>: the orbits and the paths.</li>
<li>NASA JPL, <a href="https://ssd.jpl.nasa.gov/tools/sbdb_query.html">Small-Body Database Query</a> and its <a href="https://ssd-api.jpl.nasa.gov/doc/sbdb_query.html">API</a>: the orbits of the asteroids and of the objects beyond Neptune.</li>
<li>Park, R.S., Folkner, W.M., Williams, J.G. and Boggs, D.H. (2021), <a href="https://doi.org/10.3847/1538-3881/abd414">The JPL planetary and lunar ephemerides DE440 and DE441</a>, <em>The Astronomical Journal</em> 161, 105.</li>
<li>Stone, E.C., Cummings, A.C., Heikkila, B.C. and Lal, N. (2019), <a href="https://doi.org/10.1038/s41550-019-0928-3">Cosmic ray measurements from Voyager 2 as it crossed into interstellar space</a>, <em>Nature Astronomy</em> 3, 1013–1018.</li>
<li>Trujillo, C.A. and Brown, M.E. (2001), <a href="https://doi.org/10.1086/320917">The radial distribution of the Kuiper belt</a>, <em>The Astrophysical Journal</em> 554, L95–L98.</li>
</ul>
<p><em>Rendered with R 4.6.2 · plotly · jsonlite</em></p>
<!-- -->
</section>
<p>This post first appeared on <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SOLAR_SYSTEM.html">Illustrations in R</a>, with its interactive charts and the full R code.</p>]]></content:encoded>
    </item>
    <item>
      <title>The Butterfly Effect: Chaos in Two Simple Machines</title>
      <link>https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_CHAOS.html</link>
      <guid isPermaLink="true">https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_CHAOS.html</guid>
      <pubDate>Wed, 02 Dec 2026 16:42:17 +0200</pubDate>
      <category>R</category>
      <category>Illustrations in R</category>
      <description>Chaos computed in R: the Lorenz system, whose path draws a butterfly in 3D (plotly), and 100 double pendulums whose starts differ by a thousandth of a degree, which swing together for a few seconds and then scatter (a GIF made with ggplot2 and magick). How fast tiny differences grow, why a gentle swing is not chaotic, and why a forecast gains so little from a more precise start.</description>
      <content:encoded><![CDATA[<p><em>Chaos computed in R: the Lorenz system, whose path draws a butterfly in 3D (plotly), and 100 double pendulums whose starts differ by a thousandth of a degree, which swing together for a few seconds and then scatter (a GIF made with ggplot2 and magick). How fast tiny differences grow, why a gentle swing is not chaotic, and why a forecast gains so little from a more precise start.</em></p>
<section id="what-is-this" class="level2">
<h2 class="anchored" data-anchor-id="what-is-this">What is this?</h2>
<p>Some machines follow exact rules, with nothing left to chance, and still cannot be predicted for long: a difference too small to measure at the start grows until it is as large as the motion itself. This is <strong>chaos</strong>, and its best-known picture is the <strong>butterfly effect</strong>. This page computes two such machines in R and watches tiny differences grow. Five questions:</p>
<ol type="1">
<li><strong>What shape does the Lorenz system draw?</strong></li>
<li><strong>How fast do two almost identical starts part?</strong></li>
<li><strong>What do 100 double pendulums do?</strong></li>
<li><strong>Is a double pendulum always chaotic?</strong></li>
<li><strong>Why does a more precise start buy so little time?</strong></li>
</ol>
<p>Nothing is downloaded: every number and every picture is computed on the page from the equations of the two machines.</p>
<ul>
<li>The <strong>Lorenz system</strong> is three equations that Edward Lorenz, a meteorologist at MIT, cut down from a model of a layer of air heated from below, like water in a pot on a stove (<a href="https://doi.org/10.1175/1520-0469%281963%29020%3C0130%3ADNF%3E2.0.CO%3B2">Lorenz 1963</a>). Its three numbers stand for the air: <strong>x</strong> for how fast it turns over, <strong>y</strong> for the difference in temperature between the rising and the sinking air, and <strong>z</strong> for how far the temperature from the bottom to the top departs from a straight line.</li>
<li>The <strong>double pendulum</strong> is a pendulum that hangs from the end of another: two stiff arms of 1 m, each with a weight of 1 kg at its end, swinging in one plane, without friction (<a href="https://doi.org/10.1119/1.17335">Levien and Tan 1993</a>).</li>
</ul>
<p><strong>The words of this page:</strong></p>
<ul>
<li><strong>deterministic</strong>: the future follows from the present by fixed rules. Started twice from exactly the same point, a deterministic machine does exactly the same thing twice;</li>
<li>the <strong>state</strong> of a machine: the numbers that fix it at one moment. For the Lorenz system they are x, y and z; for a double pendulum, the angle of each arm from hanging straight down and how fast it turns;</li>
<li><strong>chaos</strong>: deterministic motion that never repeats itself, and in which any tiny difference of the start grows quickly, by doubling again and again, until the two motions have nothing in common. This is <strong>sensitive dependence on initial conditions</strong>; it is called the <strong>butterfly effect</strong> after a talk that Lorenz gave in 1972, “Predictability: does the flap of a butterfly’s wings in Brazil set off a tornado in Texas?”;</li>
<li>an <strong>attractor</strong>: the shape that the motion settles onto and keeps going round, whatever its start. The attractor of the Lorenz system looks like a butterfly;</li>
<li><strong>exponential growth</strong> and the <strong>Lyapunov exponent</strong>, λ (lambda): a gap that grows exponentially takes always the same time to double. λ measures how fast: the gap is multiplied by e (2.718) every 1/λ, doubles every ln 2/λ = 0.69/λ, and grows ten-fold every ln 10/λ = 2.30/λ;</li>
<li><strong>time units</strong>: the Lorenz system’s time has no unit of its own, because its equations are scaled; the pendulums’ time is in seconds;</li>
<li>the <strong>Runge–Kutta method</strong> (RK4): the computer moves each machine on in small steps, each time looking at how fast its state changes at the start, in the middle and at the end of the step: steps of 0.005 time units for the Lorenz system and of a thousandth of a second for the pendulums.</li>
</ul>
<hr>
</section>
<section id="packages" class="level2">
<h2 class="anchored" data-anchor-id="packages">Packages</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1"><pre><code class="language-r"># install.packages(c("plotly","ggplot2","magick","ragg"))
library(plotly)
library(ggplot2)
library(magick)</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2"><pre><code class="language-r"># short labels of numbers for the text
number&lt;-function(x) {
  result&lt;-format(round(x),big.mark=",",trim=TRUE,scientific=FALSE)
  return(result)
}
# to one or two decimals, with a minus sign rather than a hyphen: "−18.7"
one&lt;-function(x) {
  result&lt;-sub("^-","−",format(round(x,1),nsmall=1,trim=TRUE))
  return(result)
}
two&lt;-function(x) {
  result&lt;-sub("^-","−",format(round(x,2),nsmall=2,trim=TRUE))
  return(result)
}
percent&lt;-function(x) {
  result&lt;-paste0(round(x),"%")
  return(result)
}</code></pre></div></div>
</details>
</div>
</section>
<section id="the-machines" class="level2">
<h2 class="anchored" data-anchor-id="the-machines">The machines</h2>
<section id="one-step-at-a-time" class="level3">
<h3 class="anchored" data-anchor-id="one-step-at-a-time">One step at a time</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3"><pre><code class="language-r"># one step of the Runge–Kutta method (RK4): the rate of change is taken at the start of the step,
# twice halfway and at its end, and the four are averaged. Each row of the matrix s is one copy of a
# machine, so that many copies move on together
rk4_step&lt;-function(s,dt,rate) {
  k1&lt;-rate(s)
  k2&lt;-rate(s+dt/2*k1)
  k3&lt;-rate(s+dt/2*k2)
  k4&lt;-rate(s+dt*k3)
  result&lt;-s+dt/6*(k1+2*k2+2*k3+k4)
  return(result)
}</code></pre></div></div>
</details>
</div>
</section>
<section id="the-lorenz-system" class="level3">
<h3 class="anchored" data-anchor-id="the-lorenz-system">The Lorenz system</h3>
<p>Lorenz’s three equations say how fast x, y and z change at each moment: dx/dt = σ(y − x), dy/dt = x(ρ − z) − y and dz/dt = xy − βz, with σ = 10, ρ = 28 and β = 8/3, the values that he used. Every run on this page starts from the same point of the attractor: from x = y = z = 1, the system is moved on for 20 time units, by which time it has settled onto the butterfly.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4"><pre><code class="language-r">sigma&lt;-10
rho&lt;-28
beta&lt;-8/3
lorenz_rate&lt;-function(s) {
  result&lt;-cbind(sigma*(s[,2]-s[,1]),
                s[,1]*(rho-s[,3])-s[,2],
                s[,1]*s[,2]-beta*s[,3])
  return(result)
}
# copies of the system (one to a row of start) moved on together for a time, in steps of 0.005 time
# units; the state of every copy is kept every `keep` steps, as an array of time × copy × (x, y, z)
lorenz_dt&lt;-0.005
lorenz_run&lt;-function(start,time,keep=2) {
  s&lt;-start
  steps&lt;-round(time/lorenz_dt)
  result&lt;-array(NA_real_,c(steps%/%keep+1,nrow(s),3))
  result[1,,]&lt;-s
  for(k in seq_len(steps)) {
    s&lt;-rk4_step(s,lorenz_dt,lorenz_rate)
    if(k%%keep==0)
      result[k%/%keep+1,,]&lt;-s
  }
  return(result)
}
# the start of every run: x = y = z = 1, moved on for 20 time units
start&lt;-matrix(lorenz_run(matrix(1,1,3),20,keep=round(20/lorenz_dt))[2,1,],nrow=1)</code></pre></div></div>
</details>
</div>
</section>
<section id="the-double-pendulum" class="level3">
<h3 class="anchored" data-anchor-id="the-double-pendulum">The double pendulum</h3>
<p>The equations of the double pendulum follow from Newton’s laws for two arms of the same length with the same weight at their ends (<a href="https://doi.org/10.1119/1.17335">Levien and Tan 1993</a>). Each run moves 100 pendulums on together: their arms start still, the upper arms at the same angle and the lower arms <strong>0.001° apart</strong> from one pendulum to the next, so that the 100 lower arms span 0.099°.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5"><pre><code class="language-r"># the state of a pendulum: the angle of each arm from hanging straight down (theta1 for the upper
# arm, theta2 for the lower one, in radians) and how fast each turns (omega1 and omega2, radians a
# second); arms of 1 m with 1 kg at their ends, and g = 9.81 m/s²
g&lt;-9.81
pendulum_rate&lt;-function(s) {
  d&lt;-s[,1]-s[,2]
  under&lt;-3-cos(2*d)
  turn1&lt;-(-3*g*sin(s[,1])-g*sin(s[,1]-2*s[,2])-2*sin(d)*(s[,4]^2+s[,3]^2*cos(d)))/under
  turn2&lt;-2*sin(d)*(2*s[,3]^2+2*g*cos(s[,1])+s[,4]^2*cos(d))/under
  result&lt;-cbind(s[,3],s[,4],turn1,turn2)
  return(result)
}
# the energy of a pendulum, in joules more than it has hanging still; without friction it stays the
# same, which checks the computation
pendulum_energy&lt;-function(s) {
  result&lt;-s[,3]^2+s[,4]^2/2+s[,3]*s[,4]*cos(s[,1]-s[,2])-2*g*cos(s[,1])-g*cos(s[,2])+3*g
  return(result)
}
# 100 pendulums, both arms at the same angle (in degrees) and the lower arms 0.001° apart, moved on
# for 30 seconds in steps of a thousandth of a second; their states are kept every hundredth of a
# second, as an array of time × pendulum × (theta1, theta2, omega1, omega2)
pendulum_run&lt;-function(angle,n=100,apart=0.001,seconds=30,dt=0.001,keep=10) {
  s&lt;-cbind(angle*pi/180,(angle+(seq_len(n)-1)*apart)*pi/180,0,0)
  steps&lt;-round(seconds/dt)
  result&lt;-array(NA_real_,c(steps%/%keep+1,n,4))
  result[1,,]&lt;-s
  for(k in seq_len(steps)) {
    s&lt;-rk4_step(s,dt,pendulum_rate)
    if(k%%keep==0)
      result[k%/%keep+1,,]&lt;-s
  }
  return(result)
}
gentle_angle&lt;-20
wild_angle&lt;-120
gentle&lt;-pendulum_run(gentle_angle)
wild&lt;-pendulum_run(wild_angle)
pendulum_time&lt;-(seq_len(dim(wild)[1])-1)*0.01
# where the weight at the end of each lower arm is: x to the right and y up, in meters from the
# pivot
tip&lt;-function(s) {
  result&lt;-cbind(sin(s[,1])+sin(s[,2]),-cos(s[,1])-cos(s[,2]))
  return(result)
}
# how far apart the 100 pendulums are at each moment: the largest distance between the ends of the
# lower arms of any two of them, in meters
spread&lt;-function(run) {
  result&lt;-apply(run,1,function(s) max(dist(tip(s))))
  return(result)
}</code></pre></div></div>
</details>
</div>
</section>
<section id="charts" class="level3">
<h3 class="anchored" data-anchor-id="charts">Charts</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6"><pre><code class="language-r">dark_gray&lt;-"#6b6b6b" # also the color of the notes
reference_gray&lt;-"#a3a3a3" # the dashed lines that compare a series with a rule
ink&lt;-"#191919"
# the colors of the series, told apart also by color-blind readers (each pair checked)
blue&lt;-"#257de0"
orange&lt;-"#f47230"
green&lt;-"#00b894"
# the source of a chart, as a note under it, and the common layout; note_shift moves the note down
# by a number of pixels, which stays the same however tall the plot is
chart&lt;-function(p,title,source,y_title="",x_title="",y_axis=list(),x_axis=list(),
                annotations=list(),margin=list(t=70,b=90),note_y=-0.16,note_shift=0,...) {
  note&lt;-list(text=paste("Source:",source),xref="paper",yref="paper",x=0,y=note_y,xanchor="left",
             yanchor="top",yshift=note_shift,align="left",showarrow=FALSE,
             font=list(size=11,color=dark_gray))
  result&lt;-layout(p,
                 title=list(text=title,x=0.02,xanchor="left",y=0.97,yanchor="top"),
                 margin=margin,
                 annotations=c(annotations,list(note)),
                 ...)
  if(nchar(paste0(y_title,x_title))&gt;0||length(c(y_axis,x_axis))&gt;0)
    result&lt;-layout(result,yaxis=modifyList(list(title=y_title),y_axis),
                   xaxis=modifyList(list(title=x_title),x_axis))
  result&lt;-config(result,displaylogo=FALSE)
  return(result)
}
legend_top&lt;-list(orientation="h",x=0,y=1.02,yanchor="bottom",itemsizing="constant")
computed&lt;-"computed on this page"
lorenz_source&lt;-paste0(computed," from Lorenz's equations (1963), with σ = 10, ρ = 28, β = 8/3.")
pendulum_source&lt;-paste(computed,"for frictionless double pendulums: arms of 1 m, weights of 1 kg.")
# a 3D chart is built once and its second copy of every number ("attrs") dropped, which halves its
# size; the path is drawn in hundredths as whole numbers, because plotly for R writes any other
# number with 17 digits (8.49 as 8.4900000000000002). The axes are hidden
finish_3d&lt;-function(p) {
  result&lt;-plotly_build(p)
  result$x$attrs&lt;-NULL
  return(result)
}
# buttons under the 3D chart that turn it to three views
views&lt;-list(Wings=list(eye=list(x=0,y=-2.2,z=0.1),up=list(x=0,y=0,z=1)),
            `From above`=list(eye=list(x=0,y=0,z=2.4),up=list(x=0,y=1,z=0)),
            `From the side`=list(eye=list(x=2.2,y=0,z=0.1),up=list(x=0,y=0,z=1)))
view_buttons&lt;-lapply(names(views),function(v)
  list(label=v,method="relayout",args=list(list(scene.camera=c(views[[v]],
                                                                list(center=list(x=0,y=0,z=0)))))))
view_menu&lt;-list(type="buttons",direction="right",x=0,y=0,xanchor="left",yanchor="top",
                showactive=FALSE,buttons=view_buttons)</code></pre></div></div>
</details>
</div>
</section>
<section id="the-movie-of-the-pendulums" class="level3">
<h3 class="anchored" data-anchor-id="the-movie-of-the-pendulums">The movie of the pendulums</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7"><pre><code class="language-r"># each pendulum in a shade of blue, from light (its lower arm started at 20° or 120°) to dark
# (0.099° more). 20 shades, each shared by 5 neighboring pendulums, keep the GIF small
ramp&lt;-c("#84b9f3","#6aabf1","#519ced","#338ced","#257de0","#2370cd","#1b64be","#1757ac","#0f4a96",
        "#0e3d7e")
shades&lt;-20
pendulum_colours&lt;-colorRampPalette(ramp)(shades)[ceiling(seq_len(100)*shades/100)]
# the arms of the pendulums at one moment, as segments, the upper arm and then the lower arm of
# each; shift moves the pivot to the right, in meters
arm_segments&lt;-function(s,shift) {
  elbow&lt;-cbind(sin(s[,1]),-cos(s[,1]))
  end&lt;-tip(s)
  n&lt;-nrow(s)
  result&lt;-data.frame(x=shift+c(rep(0,n),elbow[,1]),
                     y=c(rep(0,n),elbow[,2]),
                     xend=shift+c(elbow[,1],end[,1]),
                     yend=c(elbow[,2],end[,2]),
                     colour=rep(pendulum_colours,2),
                     pendulum=rep(seq_len(n),2))
  return(result)
}
# a frame: the gentle pendulums on the left, the wild ones on the right, the time at the bottom
shift&lt;-4.6
panel_titles&lt;-paste0(c("Gentle: both arms at ","Wild: both arms at "),
                     c(gentle_angle,wild_angle),"°")
frame_plot&lt;-function(k) {
  arms&lt;-rbind(arm_segments(gentle[k,,],0),arm_segments(wild[k,,],shift))
  arms&lt;-arms[order(arms$pendulum),]
  result&lt;-ggplot(arms)+
    geom_segment(aes(x,y,xend=xend,yend=yend,colour=colour),linewidth=0.35)+
    geom_point(aes(xend,yend,colour=colour),size=0.8)+
    annotate("point",x=c(0,shift),y=0,size=1.6,colour=ink)+
    annotate("text",x=c(0,shift),y=2.3,label=panel_titles,size=3.8,colour=ink,fontface="bold")+
    annotate("text",x=shift/2,y=-2.35,label=sprintf("%.1f s",pendulum_time[k]),size=3.8,
             colour=dark_gray)+
    scale_colour_identity()+
    coord_fixed(xlim=c(-2.2,shift+2.2),ylim=c(-2.5,2.5),expand=FALSE)+
    theme_void()+
    theme(plot.background=element_rect(fill="#ffffff",colour=NA))
  return(result)
}
# the movie: a frame every 0.08 seconds of the first 18, drawn by ggplot into png files (ragg) and
# put by magick on one palette (the blues, the inks and 24 grays, without dithering), then written
# as a GIF that plays in real time, loops and holds its last frame for about a second
movie&lt;-function(file,seconds=18,every=8,hold=12) {
  moments&lt;-seq(1,round(seconds/0.01)+1,by=every)
  frames&lt;-file.path(tempdir(),sprintf("pendulums_%03d.png",seq_along(moments)))
  on.exit(unlink(frames))
  for(k in seq_along(moments)) {
    ragg::agg_png(frames[k],width=640,height=356,res=85,background="#ffffff")
    # the png file is closed even if a frame fails, so that later plots do not go into it
    tryCatch(print(frame_plot(moments[k])),finally=dev.off())
  }
  level&lt;-round(seq(0,255,length.out=24))
  colours&lt;-unique(c(pendulum_colours,"#ffffff",ink,dark_gray,rgb(level,level,level,
                                                                  maxColorValue=255)))
  palette&lt;-image_read(as.raster(matrix(colours,nrow=1)))
  images&lt;-image_read(c(frames,rep(frames[length(frames)],hold)))
  gif&lt;-image_animate(image_map(images,palette,dither=FALSE),delay=every,optimize=TRUE)
  image_write(gif,file)
  return(file)
}
# the file of the movie: in the folder of the page's figures when the page is rendered, so that it
# is published with them, or a temporary file when the code is run by hand
gif_file&lt;-function() {
  result&lt;-if(isTRUE(getOption("knitr.in.progress"))) knitr::fig_path(".gif") else
    tempfile(fileext=".gif")
  dir.create(dirname(result),recursive=TRUE,showWarnings=FALSE)
  return(result)
}</code></pre></div></div>
</details>
</div>
<hr>
</section>
</section>
<section id="what-shape-does-the-lorenz-system-draw" class="level2">
<h2 class="anchored" data-anchor-id="what-shape-does-the-lorenz-system-draw">1. What shape does the Lorenz system draw?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8"><pre><code class="language-r">path&lt;-as.data.frame(lorenz_run(start,100)[,1,])
names(path)&lt;-c("x","y","z")
path$time&lt;-(seq_len(nrow(path))-1)*2*lorenz_dt
# a loop is one turn round one of the two holes; the path passes the top of a loop where z is
# highest. The side of each loop is the sign of x at its top
tops&lt;-which(diff(sign(diff(path$z)))&lt;0)+1
side&lt;-ifelse(path$x[tops]&lt;0,"left","right")
stays&lt;-rle(side)
switches&lt;-length(stays$lengths)-1
# the centers of the two holes: the two states, other than 0, 0, 0, where nothing changes
hole&lt;-sqrt(beta*(rho-1))</code></pre></div></div>
</details>
</div>
<p><strong>A butterfly, whose two wings the path visits in no set order.</strong> In 100 time units the path goes round 134 loops. Each loop circles one of two holes, at x = y = −8.49 or +8.49 and z = 27: the two states, besides 0, 0, 0, at which nothing would change. But they are unstable, like a pencil standing on its point: the path spirals out from one of them, a little further with every loop, until it is thrown over to the other. It switched wings 54 times, stayed for 11 loops at most on one wing and for 2.4 on average, and spent 51% of its loops on the left. It never leaves its box (x from −18.7 to 17.9, y from −25.4 to 23.9, z from 3.8 to 46.0), and it never comes back exactly to where it was: Lorenz called such motion <strong>nonperiodic</strong>. It goes round and round, never twice the same way.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9"><pre><code class="language-r">curve&lt;-data.frame(x=round(100*path$x),y=round(100*path$y),z=round(100*path$z))
wing_scale&lt;-list(list(0,blue),list(0.5,blue),list(0.5,green),list(1,green))
centres&lt;-data.frame(x=round(100*c(-hole,hole)),y=round(100*c(-hole,hole)),z=round(100*(rho-1)),
                    name=c("Left wing (x below 0)","Right wing (x above 0)"),
                    colour=c(blue,green),
                    sign=c("−","+"))
p&lt;-plot_ly(curve,x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
           line=list(color=as.numeric(path$x&gt;0),colorscale=wing_scale,cmin=0,cmax=1,width=3),
           hoverinfo="skip",showlegend=FALSE)
for(k in 1:2)
  p&lt;-add_trace(p,data=centres[k,],x=~x,y=~y,z=~z,type="scatter3d",mode="markers",
               name=centres$name[k],inherit=FALSE,
               marker=list(color=centres$colour[k],size=7,line=list(color="#ffffff",width=2)),
               hovertemplate=paste0("&lt;b&gt;Centre of the ",tolower(sub(" \\(.*","",centres$name[k])),
                                    "&lt;/b&gt;&lt;br&gt;x = y = ",centres$sign[k],two(hole),", z = ",
                                    number(rho-1),"&lt;br&gt;the path circles it but never ",
                                    "reaches it&lt;extra&gt;&lt;/extra&gt;"))
p %&gt;%
  chart("The path of the Lorenz system, 100 time units",
        paste(lorenz_source,"Drag to turn, scroll to zoom."),
        margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,legend=legend_top,
        scene=list(xaxis=list(visible=FALSE),yaxis=list(visible=FALSE),zaxis=list(visible=FALSE),
                   aspectmode="data",dragmode="turntable",
                   camera=list(eye=list(x=0.5,y=-2,z=0.5))),
        updatemenus=list(view_menu)) %&gt;%
  finish_3d()</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_CHAOS.html">Interactive chart: The path of the Lorenz system, 100 time units</a></p>
</div>
</div>
<p>The color shows the wing: blue where x is below 0, green where it is above. Turned <strong>From above</strong>, the two wings make a figure of eight; <strong>From the side</strong>, they lie one behind the other, each a round disc of loops around its center.</p>
<hr>
</section>
<section id="how-fast-do-two-almost-identical-starts-part" class="level2">
<h2 class="anchored" data-anchor-id="how-fast-do-two-almost-identical-starts-part">2. How fast do two almost identical starts part?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10"><pre><code class="language-r"># two runs from the same start, the second 0.00000001 further along x
nudge&lt;-1e-8
pair&lt;-lorenz_run(rbind(start,start+c(nudge,0,0)),40)
runs&lt;-data.frame(time=(seq_len(dim(pair)[1])-1)*2*lorenz_dt,first=pair[,1,1],second=pair[,2,1])
runs$gap&lt;-sqrt(rowSums((pair[,1,]-pair[,2,])^2))
apart&lt;-runs$time[which(runs$gap&gt;1)[1]]
# the typical distance between two points of the butterfly: the mean distance between 2,000 pairs of
# points of the path of question 1, chosen at random
set.seed(1)
first_points&lt;-as.matrix(path[sample(nrow(path),2000,replace=TRUE),c("x","y","z")])
second_points&lt;-as.matrix(path[sample(nrow(path),2000,replace=TRUE),c("x","y","z")])
typical&lt;-mean(sqrt(rowSums((first_points-second_points)^2)))
unrelated&lt;-runs$time[which(runs$gap&gt;typical)[1]]
# the Lyapunov exponent: two copies 0.00000001 apart are moved on for 500 time units; every 0.1 time
# units the gap is measured, and shrunk back to 0.00000001 along the same direction so that it stays
# tiny. Its average growth rate is lambda (Benettin et al. 1980)
lyapunov&lt;-function(start,time=500,every=0.1,size=1e-8) {
  copies&lt;-rbind(start,start+c(size,0,0))
  growth&lt;-0
  rounds&lt;-round(time/every)
  for(r in seq_len(rounds)) {
    for(k in seq_len(round(every/lorenz_dt)))
      copies&lt;-rk4_step(copies,lorenz_dt,lorenz_rate)
    gap&lt;-sqrt(sum((copies[2,]-copies[1,])^2))
    growth&lt;-growth+log(gap/size)
    copies[2,]&lt;-copies[1,]+(copies[2,]-copies[1,])*size/gap
  }
  result&lt;-growth/(rounds*every)
  return(result)
}
lambda&lt;-lyapunov(start)</code></pre></div></div>
</details>
</div>
<p><strong>Together for 20 time units, then apart.</strong> The second run starts 0.00000001 (a hundred-millionth) further along x than the first. On the chart below their x lies on one line until about t = 20.3, when the gap between them passes 1; then they go their own ways, and from t = 24.1 the gap is as large as the typical distance between two points of the butterfly, 18.6: the two runs have no more in common than two points taken at random.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11"><pre><code class="language-r">plot_ly(runs,x=~time) %&gt;%
  add_trace(y=~first,type="scatter",mode="lines",name="First start",
            line=list(color=blue,width=2),hovertemplate="First start: %{y:.2f}&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  add_trace(y=~second,type="scatter",mode="lines",name="Start 0.00000001 further along x",
            line=list(color=orange,width=2),
            hovertemplate="Second start: %{y:.2f}&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  chart("x of two runs that start a hundred-millionth apart",lorenz_source,"x",
        "Time (time units of the Lorenz system)",
        x_axis=list(range=c(0,max(runs$time)),showgrid=FALSE),
        y_axis=list(zeroline=FALSE),
        shapes=list(list(type="line",x0=apart,x1=apart,y0=0,y1=1,yref="paper",
                         line=list(color=reference_gray,width=1.5,dash="dot"))),
        annotations=list(list(x=apart,y=1,yref="paper",text="they part",showarrow=FALSE,
                              xanchor="right",yanchor="top",xshift=-4,
                              font=list(size=12,color=dark_gray))),
        hovermode="x unified",legend=legend_top,margin=list(t=100,b=110),note_y=-0.28)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_CHAOS.html">Interactive chart: x of two runs that start a hundred-millionth apart</a></p>
</div>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12"><pre><code class="language-r">rule&lt;-data.frame(time=c(0,log(typical/nudge)/lambda))
rule$gap&lt;-nudge*exp(lambda*rule$time)
plot_ly(runs,x=~time,y=~gap,type="scatter",mode="lines",line=list(color=blue,width=2),
        showlegend=FALSE,hovertemplate="Gap: %{y:.2e}&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  add_trace(data=rule,x=~time,y=~gap,type="scatter",mode="lines",hoverinfo="skip",
            line=list(color=reference_gray,width=1.5,dash="dash")) %&gt;%
  chart("The gap between the two runs, on a log scale",lorenz_source,
        "Distance between the two states","Time (time units of the Lorenz system)",
        y_axis=list(type="log",exponentformat="power",dtick=2),
        x_axis=list(range=c(0,max(runs$time)),showgrid=FALSE),
        annotations=list(list(x=rule$time[2]/2,y=log10(nudge*exp(lambda*rule$time[2]/2)),
                              text=paste0("doubling every ",two(log(2)/lambda)," time units"),
                              showarrow=FALSE,xanchor="left",yanchor="top",xshift=8,
                              font=list(size=12,color=dark_gray))),
        margin=list(t=70,b=110),note_y=-0.28)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_CHAOS.html">Interactive chart: The gap between the two runs, on a log scale</a></p>
</div>
</div>
<p><strong>On a log scale, growth by doubling is a straight line</strong>, and the gap follows one, zigzagging as the runs go round their loops. The Lyapunov exponent of the Lorenz system, computed on this page over 500 time units, is λ = <strong>0.90</strong>: a tiny gap doubles every <strong>0.77 time units</strong> and grows ten-fold every 2.57. At that rate a gap of a hundred-millionth reaches 18.6 in 23.8 time units; the two runs took 24.1. After that the gap cannot grow any more, since nothing on the butterfly is further apart than its two ends, and it wanders.</p>
<hr>
</section>
<section id="what-do-100-double-pendulums-do" class="level2">
<h2 class="anchored" data-anchor-id="what-do-100-double-pendulums-do">3. What do 100 double pendulums do?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13"><pre><code class="language-r">gentle_spread&lt;-spread(gentle)
wild_spread&lt;-spread(wild)
first_time&lt;-function(spread,size) {
  result&lt;-pendulum_time[which(spread&gt;size)[1]]
  return(result)
}
wild_cm&lt;-first_time(wild_spread,0.01)
wild_10cm&lt;-first_time(wild_spread,0.1)
wild_m&lt;-first_time(wild_spread,1)
start_gap&lt;-1000*wild_spread[1]</code></pre></div></div>
</details>
</div>
<p><strong>Together for about 5 seconds, then scattered.</strong> The lower arms of the 100 pendulums start within 0.099° of each other, so the weights at their ends start within 1.7 mm: on the movie they look like one pendulum. The wild pendulums, started with both arms at 120°, are 1 cm apart after 2.2 seconds, still too little to see; 10 cm apart after 5.3, when the movie shows them as a narrow wedge; and more than a meter apart after 7.0. Then they open like a fan, flip over the top one after another, and before the end of the movie they are everywhere their arms can reach. The gentle pendulums, started at 20°, are still one at the end.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14"><pre><code class="language-r">knitr::include_graphics(movie(gif_file()))</code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_CHAOS_files/figure-html/pendulum_movie-1.gif" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><img src="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_CHAOS_files/figure-html/pendulum_movie-1.gif" class="img-fluid figure-img" style="width:100.0%" loading="lazy" alt="Movie of two sets of 100 double pendulums drawn in shades of blue, 18 seconds in real time. On the left, started with both arms at 20 degrees, the pendulums swing as one from start to end. On the right, started with both arms at 120 degrees, they swing as one for about 5 seconds, then open like a fan and scatter in every direction"></a></p>
</figure>
</div>
</div>
</div>
<p>The shade of each pendulum is the angle at which its lower arm started, from light blue (120° or 20°) to dark blue (0.099° more). While the fan opens, the shades still run in order from one edge to the other; once the pendulums scatter, the light and the dark are mixed. A real double pendulum does the same: Shinbrot and colleagues measured how fast small differences grow on one (<a href="https://doi.org/10.1119/1.16860">Shinbrot et al.&nbsp;1992</a>).</p>
<hr>
</section>
<section id="is-a-double-pendulum-always-chaotic" class="level2">
<h2 class="anchored" data-anchor-id="is-a-double-pendulum-always-chaotic">4. Is a double pendulum always chaotic?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15"><pre><code class="language-r"># the growth rate while the gap is small: from 1 cm to 10 cm
pendulum_lambda&lt;-log(10)/(wild_10cm-wild_cm)
energy_gentle&lt;-pendulum_energy(gentle[1,,])[1]
energy_wild&lt;-pendulum_energy(wild[1,,])[1]
# the largest change of the energy of any pendulum during the 30 seconds, as a share of its own
# energy at the start (a matrix of pendulum × time, divided by its first column)
energy_change&lt;-function(run) {
  energy&lt;-apply(run,1,pendulum_energy)
  result&lt;-max(abs(energy/energy[,1]-1))
  return(result)
}
drift&lt;-max(energy_change(gentle),energy_change(wild))
gentle_most&lt;-1000*max(gentle_spread)</code></pre></div></div>
</details>
</div>
<p><strong>No: only when it swings hard enough.</strong> With both arms at 20°, the 100 pendulums stay together: in 30 seconds the weights at their ends are never more than 2.6 mm apart, against 1.7 mm at the start. Small swings are regular: the two arms rock in a mix of two steady rhythms, and a small difference grows slowly, at most in step with the time, never by doubling. Started at 120°, the pendulums have 25 times as much energy (44.1 joules more than hanging still, against 1.8), enough to swing over the top; then the gap between them doubles about every <strong>0.91 seconds</strong>, until it fills the circle that their arms can reach.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16"><pre><code class="language-r">every&lt;-seq(1,length(pendulum_time),by=5)
spreads&lt;-data.frame(time=pendulum_time[every],gentle=1000*gentle_spread[every],
                    wild=1000*wild_spread[every])
# the name of each line at its right end: the gentle line at the top of its swings, the wild one
# where it ends
label_y&lt;-c(gentle=log10(gentle_most),wild=log10(spreads$wild[nrow(spreads)]))
end_labels&lt;-lapply(c("gentle","wild"),function(v)
  list(x=max(spreads$time),y=label_y[[v]],text=if(v=="gentle") "Gentle" else "Wild",
       showarrow=FALSE,xanchor="left",xshift=6,font=list(size=12,color=ink)))
plot_ly(spreads,x=~time) %&gt;%
  add_trace(y=~gentle,type="scatter",mode="lines",name=paste0("Gentle: arms at ",gentle_angle,"°"),
            line=list(color=green,width=2),hovertemplate="Gentle: %{y:.1f} mm&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  add_trace(y=~wild,type="scatter",mode="lines",name=paste0("Wild: arms at ",wild_angle,"°"),
            line=list(color=orange,width=2),hovertemplate="Wild: %{y:.0f} mm&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  chart("How far apart the 100 pendulums are",pendulum_source,
        "Largest distance between two of them","Time (seconds)",
        y_axis=list(type="log",tickvals=c(1,10,100,1000),ticktext=c("1 mm","1 cm","10 cm","1 m"),
                    range=c(-0.2,3.6)),
        x_axis=list(showgrid=FALSE),annotations=end_labels,
        hovermode="x unified",legend=legend_top,margin=list(t=100,b=110,r=60),note_y=-0.28)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_CHAOS.html">Interactive chart: How far apart the 100 pendulums are</a></p>
</div>
</div>
<p>The computation can be checked: a pendulum without friction neither gains nor loses energy, and the energy of every pendulum stayed the same to within one part in 100,000,000 over the 30 seconds. So the steps are small enough, and the scattering comes from the pendulum, not from the arithmetic.</p>
<hr>
</section>
<section id="why-does-a-more-precise-start-buy-so-little-time" class="level2">
<h2 class="anchored" data-anchor-id="why-does-a-more-precise-start-buy-so-little-time">5. Why does a more precise start buy so little time?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17"><pre><code class="language-r"># 40 starts along the path of question 1, one every 2.5 time units. Each is rounded to 1, 2, ... 12
# decimals, as if copied from a printout, and moved on together with the exact start: when does
# each rounded run part from the exact one (the gap passes 1)? A matrix of start × decimals
digits&lt;-1:12
parting_times&lt;-function(exact,digits,time=60,size=1) {
  n&lt;-nrow(exact)
  rounded&lt;-do.call(rbind,lapply(digits,function(d) round(exact,d)))
  s&lt;-rbind(exact,rounded)
  partner&lt;-rep(seq_len(n),length(digits))
  parted&lt;-rep(NA_real_,nrow(rounded))
  for(k in seq_len(round(time/lorenz_dt))) {
    s&lt;-rk4_step(s,lorenz_dt,lorenz_rate)
    gap&lt;-sqrt(rowSums((s[n+seq_len(nrow(rounded)),]-s[partner,])^2))
    parted[is.na(parted)&amp;gap&gt;size]&lt;-k*lorenz_dt
  }
  stopifnot(!anyNA(parted))
  result&lt;-matrix(parted,nrow=n)
  return(result)
}
exact&lt;-as.matrix(path[match(seq(2.5,100,by=2.5),round(path$time,2)),c("x","y","z")])
times&lt;-parting_times(exact,digits)
part&lt;-colMeans(times)
part_low&lt;-apply(times,2,quantile,0.1)
part_high&lt;-apply(times,2,quantile,0.9)
fit&lt;-lm(part~digits)
per_digit&lt;-coef(fit)[["digits"]]</code></pre></div></div>
</details>
</div>
<p><strong>Each extra decimal buys the same short time: about 2.52 time units.</strong> On average over 40 starts along the butterfly, a run started from its state rounded to 3 decimals parts from the exact one at t = 7.5; rounded to 6 decimals, at t = 15.6; rounded to 12, a start a billion times more precise than with 3, at t = 30.0, only 4.0 times as long. Every decimal makes the first gap ten times smaller, and the system takes ln 10/λ = 2.57 time units, on average, to grow a gap ten-fold: so each decimal adds about that much time, and to see twice as far ahead the start has to be known to about twice as many decimals. From one start to another the time varies (the bars hold the middle 80% of the starts), because the butterfly stretches a gap faster in some places than in others.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18"><pre><code class="language-r">fitted&lt;-data.frame(digits=range(digits),time=predict(fit,data.frame(digits=range(digits))))
averages&lt;-data.frame(digits=digits,time=part,low=part-part_low,high=part_high-part)
plot_ly(averages,x=~digits,y=~time,type="scatter",mode="markers",
        marker=list(color=blue,size=9,line=list(color="#ffffff",width=2)),showlegend=FALSE,
        error_y=list(type="data",symmetric=FALSE,array=~high,arrayminus=~low,color=blue,
                     thickness=1.5,width=0),
        hovertemplate="%{x} decimals: they part at t = %{y:.1f} on average&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  add_trace(data=fitted,x=~digits,y=~time,type="scatter",mode="lines",hoverinfo="skip",
            line=list(color=reference_gray,width=1.5,dash="dash"),showlegend=FALSE,
            inherit=FALSE) %&gt;%
  chart("When a rounded start parts from the exact one",lorenz_source,
        "Average time until they part (time units)","Decimals of the start",
        x_axis=list(dtick=1,showgrid=FALSE),y_axis=list(rangemode="tozero"),
        annotations=list(list(x=mean(digits),y=predict(fit,data.frame(digits=mean(digits))),
                              text=paste0("+",two(per_digit)," for every decimal"),
                              showarrow=FALSE,xanchor="left",yanchor="top",xshift=10,
                              font=list(size=12,color=dark_gray))),
        margin=list(t=70,b=110),note_y=-0.28)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_CHAOS.html">Interactive chart: When a rounded start parts from the exact one</a></p>
</div>
</div>
<p>Lorenz met this by accident in 1961, when he restarted a run of a small weather model from numbers that he had typed in from a printout. The printout showed fewer decimals than the computer kept, and the new run soon had nothing in common with the old one (Lorenz 1993). In his talk of 1972 he put the same rule in terms of the weather: small errors in the large weather patterns double in about three days, so every halving of the errors of observation would add three days to a good forecast; but small errors in the finer structure, such as the positions of single clouds, grow much faster and soon spread to the large patterns, so that “the hopes for predicting two weeks or more in advance are thus greatly diminished”. Half a century later the numbers agree: a good forecast of each day’s weather in the middle latitudes reaches about <strong>10 days ahead</strong>, and a start ten times more precise would add <strong>up to 5 more</strong> (<a href="https://doi.org/10.1175/JAS-D-18-0269.1">Zhang et al.&nbsp;2019</a>).</p>
<hr>
</section>
<section id="so-what-does-it-mean" class="level2">
<h2 class="anchored" data-anchor-id="so-what-does-it-mean">So, what does it mean?</h2>
<p><strong>Chaos is not chance: it is a rule that turns tiny differences into large ones, quickly.</strong></p>
<ol type="1">
<li><strong>The Lorenz system</strong> draws a butterfly whose 134 loops in 100 time units switch wings 54 times, in no set order, and never repeat.</li>
<li><strong>Two runs a hundred-millionth apart</strong> stay together for 20 time units and are unrelated after 24: a tiny gap doubles every 0.77 time units.</li>
<li><strong>100 double pendulums 0.001° apart</strong> swing as one for about 5 seconds and are scattered after 7.</li>
<li><strong>A gentle swing is not chaotic:</strong> at 20° the pendulums stay together; chaos needs enough energy for the arms to fold and flip.</li>
<li><strong>Precision buys little time:</strong> every extra decimal of the start adds the same 2.52 time units, which is why weather forecasts improve slowly, and why they may never reach far beyond two weeks.</li>
</ol>
<p><strong>What this does not show.</strong> The Lorenz system is a three-number cartoon of air heated from below, not a model of the atmosphere, and its time units are not days. Real weather has motions of every size, whose errors grow at different speeds: the small ones fastest, and they spill into the large ones (<a href="https://doi.org/10.3402/tellusa.v21i3.10086">Lorenz 1969</a>), which is why more precise observations alone cannot push the limit of forecasts back for ever. The pendulums are ideal: no friction, no air, stiff arms with all their weight at the ends. A real one slows down, and the times on this page hold for these starts only; other starts give other times, but the same picture. And no computer can follow one chaotic path exactly for long: its own rounding errors, in the 16th digit, grow like any other tiny difference. What a computation shows reliably is how fast differences grow and the shape of the motion, not where one pendulum will be after a minute.</p>
<hr>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<ul>
<li>Benettin, G., Galgani, L., Giorgilli, A. and Strelcyn, J.-M. (1980), <a href="https://doi.org/10.1007/BF02128237">Lyapunov characteristic exponents for smooth dynamical systems and for Hamiltonian systems; a method for computing all of them. Part 2: Numerical application</a>, <em>Meccanica</em> 15, 21–30: the computation of λ.</li>
<li>Levien, R.B. and Tan, S.M. (1993), <a href="https://doi.org/10.1119/1.17335">Double pendulum: an experiment in chaos</a>, <em>American Journal of Physics</em> 61, 1038–1044: the equations of the double pendulum.</li>
<li>Lorenz, E.N. (1963), <a href="https://doi.org/10.1175/1520-0469%281963%29020%3C0130%3ADNF%3E2.0.CO%3B2">Deterministic nonperiodic flow</a>, <em>Journal of the Atmospheric Sciences</em> 20, 130–141: the three equations, and what x, y and z stand for.</li>
<li>Lorenz, E.N. (1969), <a href="https://doi.org/10.3402/tellusa.v21i3.10086">The predictability of a flow which possesses many scales of motion</a>, <em>Tellus</em> 21, 289–307.</li>
<li>Lorenz, E.N. (1972), Predictability: does the flap of a butterfly’s wings in Brazil set off a tornado in Texas?, talk before the American Association for the Advancement of Science, 29 December 1972.</li>
<li>Lorenz, E.N. (1993), <em>The Essence of Chaos</em>, University of Washington Press: the restart of 1961.</li>
<li>Shinbrot, T., Grebogi, C., Wisdom, J. and Yorke, J.A. (1992), <a href="https://doi.org/10.1119/1.16860">Chaos in a double pendulum</a>, <em>American Journal of Physics</em> 60, 491–499.</li>
<li>Sparrow, C. (1982), <a href="https://doi.org/10.1007/978-1-4612-5767-7">The Lorenz Equations: Bifurcations, Chaos, and Strange Attractors</a>, Springer: the two centers of the wings and the attractor.</li>
<li>Zhang, F. and others (2019), <a href="https://doi.org/10.1175/JAS-D-18-0269.1">What is the predictability limit of midlatitude weather?</a>, <em>Journal of the Atmospheric Sciences</em> 76, 1077–1091.</li>
<li><a href="https://docs.ropensci.org/magick/">magick</a> and <a href="https://ragg.r-lib.org/">ragg</a>, the R packages that make the GIF.</li>
</ul>
<p><em>Rendered with R 4.6.2 · plotly · ggplot2 · magick · ragg</em></p>
<!-- -->
</section>
<p>This post first appeared on <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_CHAOS.html">Illustrations in R</a>, with its interactive charts and the full R code.</p>]]></content:encoded>
    </item>
    <item>
      <title>The Brain in Sections: Sagittal, Coronal and Transverse Slices</title>
      <link>https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_SECTIONS.html</link>
      <guid isPermaLink="true">https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_SECTIONS.html</guid>
      <pubDate>Mon, 30 Nov 2026 15:29:12 +0200</pubDate>
      <category>R</category>
      <category>Illustrations in R</category>
      <description>Movies of the human brain cut slice by slice in its three planes, drawn with ggplot2 and made into GIFs with magick from the MNI305 average brain that FreeSurfer keeps as fsaverage: what a sagittal, a coronal and a transverse section show, from the lobes to the thalamus, the basal ganglia and the hippocampus, and why white matter looks white on an MRI scan.</description>
      <content:encoded><![CDATA[<p><em>Movies of the human brain cut slice by slice in its three planes, drawn with ggplot2 and made into GIFs with magick from the MNI305 average brain that FreeSurfer keeps as fsaverage: what a sagittal, a coronal and a transverse section show, from the lobes to the thalamus, the basal ganglia and the hippocampus, and why white matter looks white on an MRI scan.</em></p>
<section id="what-is-this" class="level2">
<h2 class="anchored" data-anchor-id="what-is-this">What is this?</h2>
<p>An MRI scanner sees the head as a stack of thin slices, and doctors and neuroscientists look at the brain one slice at a time, in three planes at right angles to each other. This page cuts the average human brain in each of the three planes, from one side to the other, draws every slice with ggplot2 and joins the slices into a movie. Five questions:</p>
<ol type="1">
<li><strong>How is the brain cut?</strong></li>
<li><strong>What does a sagittal section show?</strong></li>
<li><strong>What does a coronal section show?</strong></li>
<li><strong>What does a transverse section show?</strong></li>
<li><strong>Why does white matter look white?</strong></li>
</ol>
<p>The scan is <strong>MNI305</strong>, the average of the MRI scans of 305 young adults, laid over each other after each was turned and stretched to the same size (<a href="https://doi.org/10.1109/NSSMIC.1993.373602">Evans et al.&nbsp;1993</a>). FreeSurfer, a widely used program for measuring the brain on MRI scans, keeps it with everything but the brain taken away as the scan of its average brain, <strong>fsaverage</strong> (<a href="https://openwetware.org/wiki/Beauchamp:FSAverageReadme">FreeSurfer’s notes on fsaverage</a>). The labels come with it: FreeSurfer’s <strong>segmentation</strong> of fsaverage, which names the structure that each cube of 1 mm lies in (<a href="https://doi.org/10.1016/S0896-6273(02)00569-X">Fischl et al.&nbsp;2002</a>). The lobes of the cortex come from the <strong>Desikan–Killiany atlas</strong> of fsaverage’s surface (<a href="https://doi.org/10.1016/j.neuroimage.2006.01.021">Desikan et al.&nbsp;2006</a>), which comes with the R packages ggseg.formats and ggseg.meshes (<a href="https://doi.org/10.1177/2515245920928009">Mowinckel and Vidal-Piñeiro 2020</a>). The scan and the labels, 1.9 MB and 0.4 MB, are downloaded once from the server of the fsbrain package (<a href="https://doi.org/10.1101/2020.09.18.302935">Schäfer and Ecker 2020</a>). It is the same brain as on <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Inside the Human Brain</a>, which shows its parts in 3D.</p>
<p><strong>The words of this page:</strong></p>
<ul>
<li>a <strong>section</strong> (or slice) is the face of a cut through the brain. The three <strong>planes</strong> of the cuts are (<a href="https://openstax.org/books/anatomy-and-physiology-2e/pages/1-6-anatomical-terminology">Betts et al.&nbsp;2022</a>):
<ul>
<li><strong>sagittal</strong>: it divides left from right. The <strong>midsagittal</strong> plane runs down the middle, between the two hemispheres;</li>
<li><strong>coronal</strong> (or frontal): it divides front from back;</li>
<li><strong>transverse</strong> (or horizontal; on MRI scans usually <strong>axial</strong>): it divides top from bottom;</li>
</ul></li>
<li>a <strong>T1-weighted</strong> scan is the kind of MRI scan made to show the anatomy of the brain: white matter comes out light, gray matter darker and fluid dark (question 5 says why);</li>
<li><strong>gray matter</strong> is made of the bodies of nerve cells: the <strong>cortex</strong>, the folded outer layer of the brain, and the <strong>nuclei</strong>, lumps of gray matter deep inside it. <strong>White matter</strong> is made of their long fibers, wrapped in a fatty sheath, <strong>myelin</strong>. The <strong>ventricles</strong> are the hollows in the middle of the brain, filled with fluid;</li>
<li>the <strong>cerebrum</strong> is the two hemispheres, by far the largest part of the brain. Its cortex is folded into ridges, <strong>gyri</strong> (one <em>gyrus</em>), and grooves, <strong>sulci</strong> (one <em>sulcus</em>); the deepest groove on the side of each hemisphere is the <strong>lateral sulcus</strong>. The <strong>medial wall</strong> is the part of the inner face of each hemisphere where it joins the structures under it;</li>
<li>a <strong>segmentation</strong> gives each cube of a scan the name of the part of the brain that it lies in; an <strong>atlas</strong> does the same for an average brain, here for the points of the surface of its cortex;</li>
<li>a <strong>voxel</strong> is a small cube of the scan, here 1 mm on each side: a pixel in three dimensions;</li>
<li><strong>coordinates</strong> are in mm, in the frame of MNI305: <strong>x</strong> runs from the left (−) to the right (+), <strong>y</strong> from the back (−) to the front (+), and <strong>z</strong> from the bottom (−) to the top (+). The point 0, 0, 0 lies near the <strong>anterior commissure</strong>, a small bundle of fibers that crosses between the hemispheres;</li>
<li><strong>left and right</strong>: the pictures show the brain’s left on the left, as if seen from the left side, from behind or from above. This is the <strong>neurological convention</strong>; hospitals often show the brain’s left on the right of the picture, the <strong>radiological convention</strong> (<a href="https://nipy.org/nibabel/neuro_radio_conventions.html">nibabel’s notes</a>).</li>
</ul>
<p><strong>The parts of the brain on the movies</strong>, and what they do, simplified as on <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Inside the Human Brain</a>:</p>
<ul>
<li>the <strong>lobes</strong> of the cerebrum: the <strong>frontal</strong> lobe (planning, deciding, speaking and moving), the <strong>parietal</strong> lobe (touch, and where things are), the <strong>temporal</strong> lobe (hearing, language and memory) and the <strong>occipital</strong> lobe (seeing). The atlas counts two more parts of the cortex as lobes of their own: the <strong>cingulate gyrus</strong>, along the inner face of each hemisphere (emotion, attention and memory), and the <strong>insula</strong>, hidden deep in the lateral sulcus (feelings from inside the body, and taste);</li>
<li>the <strong>basal ganglia</strong>, nuclei of movement, habits and reward: the <strong>caudate nucleus</strong>, the <strong>putamen</strong>, the <strong>globus pallidus</strong> and the <strong>nucleus accumbens</strong>;</li>
<li>the <strong>thalamus</strong>, the relay station of the senses on their way to the cortex, and under it the <strong>ventral diencephalon</strong>, FreeSurfer’s name for the hypothalamus (hunger, sleep, hormones) and the small nuclei and bundles of fibers around it;</li>
<li>the <strong>hippocampus</strong> (making new memories) and the <strong>amygdala</strong> (emotion and fear), inside the temporal lobe;</li>
<li>the <strong>corpus callosum</strong>, the bridge of fibers between the two hemispheres;</li>
<li>the <strong>cerebellum</strong> (balance and the timing of movements) and the <strong>brain stem</strong> (breathing, heartbeat, sleep and waking), under the back of the cerebrum.</li>
</ul>
<hr>
</section>
<section id="packages" class="level2">
<h2 class="anchored" data-anchor-id="packages">Packages</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1"><pre><code class="language-r"># install.packages(c("ggplot2","magick","ragg","ggrepel","freesurferformats","ggseg.formats",
#                    "ggseg.meshes","FNN"))
library(ggplot2)
library(magick)</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2"><pre><code class="language-r"># short labels of numbers and lists for the text
number&lt;-function(x) {
  result&lt;-format(round(x),big.mark=",",trim=TRUE)
  return(result)
}
one&lt;-function(x) {
  result&lt;-format(round(x,1),nsmall=1,trim=TRUE)
  return(result)
}
percent&lt;-function(x) {
  result&lt;-paste0(round(x),"%")
  return(result)
}
and_list&lt;-function(x) {
  result&lt;-if(length(x)&lt;2) paste(x) else paste(paste(x[-length(x)],collapse=", "),"and",
                                               x[length(x)])
  return(result)
}
lower_first&lt;-function(x) {
  result&lt;-paste0(tolower(substr(x,1,1)),substring(x,2))
  return(result)
}
# a coordinate with its sign, and a minus sign rather than a hyphen: "+4", "−24", "0"
signed&lt;-function(x) {
  result&lt;-paste0(if(x&gt;0) "+" else if(x&lt;0) "−" else "",abs(x))
  return(result)
}</code></pre></div></div>
</details>
</div>
</section>
<section id="the-data" class="level2">
<h2 class="anchored" data-anchor-id="the-data">The data</h2>
<section id="the-scan-and-its-labels" class="level3">
<h3 class="anchored" data-anchor-id="the-scan-and-its-labels">The scan and its labels</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3"><pre><code class="language-r"># fsaverage keeps both volumes as 256 × 256 × 256 cubes of 1 mm: brain.mgz, the scan with everything
# but the brain taken away, and aseg.mgz, the label of each cube (FreeSurfer numbers them: 3 is the
# cortex of the left hemisphere, 17 the left hippocampus...). The server of the fsbrain package keeps
# a copy of both. The page keeps its download: a file is downloaded into a temporary file first,
# which takes its place only if its checksum is that of the file the page was written for, so that
# a download cut off halfway is never kept
cached_file&lt;-function(url,file,md5,tries=3) {
  if(file.exists(file)&amp;&amp;unname(tools::md5sum(file))==md5)
    return(file)
  part&lt;-paste0(file,".part")
  for(k in seq_len(tries)) {
    done&lt;-tryCatch(download.file(url,part,mode="wb",quiet=TRUE)==0,error=function(e) FALSE)
    if(done&amp;&amp;unname(tools::md5sum(part))==md5) {
      file.rename(part,file)
      return(file)
    }
    if(k&lt;tries)
      Sys.sleep(10)
  }
  unlink(part)
  stop("Could not download ",url," with the expected checksum")
}
cache&lt;-tools::R_user_dir("illustration","cache")
dir.create(cache,recursive=TRUE,showWarnings=FALSE)
server&lt;-"https://rcmd.org/projects/nitestdata/subjects_dir/fsaverage/mri/"
checksums&lt;-c(brain="b8bc4b5854f2d5e66d5c4f95d4f9cf63",aseg="b4a8f385370e5c831cdbe2f2a00d2d51")
volumes&lt;-list()
for(v in names(checksums)) {
  file&lt;-cached_file(paste0(server,v,".mgz"),file.path(cache,paste0("fsaverage_",v,".mgz")),
                    checksums[[v]])
  volumes[[v]]&lt;-freesurferformats::read.fs.mgh(file,with_header=TRUE)
}
# the cubes are stored from right to left, from top to bottom and from back to front. Turned round,
# they run from left to right (x), from back to front (y) and from bottom to top (z), the axes of
# MNI305; mm holds the coordinate of each row of cubes along each axis. Both volumes have 256 cubes
# along each side and the same frame
voxel_matrix&lt;-freesurferformats::mghheader.vox2ras(volumes$aseg$header)
stopifnot(all(voxel_matrix[1:3,1:3]==rbind(c(-1,0,0),c(0,0,1),c(0,-1,0))),
          all(dim(volumes$aseg$data)[1:3]==256),all(dim(volumes$brain$data)[1:3]==256),
          isTRUE(all.equal(freesurferformats::mghheader.vox2ras(volumes$brain$header),
                           voxel_matrix)))
turn&lt;-function(volume) {
  result&lt;-aperm(volume[256:1,256:1,,1],c(1,3,2))
  return(result)
}
scan&lt;-turn(volumes$brain$data)
labels&lt;-turn(volumes$aseg$data)
mm&lt;-list(x=sort(voxel_matrix[1,1]*(0:255)+voxel_matrix[1,4]),
         y=sort(voxel_matrix[2,3]*(0:255)+voxel_matrix[2,4]),
         z=sort(voxel_matrix[3,2]*(0:255)+voxel_matrix[3,4]))
# a check of the turn: 1,000 cubes of the brain, taken at random, keep their labels at the
# coordinates that FreeSurfer gives them
set.seed(1)
stored&lt;-which(volumes$aseg$data[,,,1]&gt;0,arr.ind=TRUE)
stored&lt;-stored[sample(nrow(stored),1000),1:3]
xyz&lt;-(cbind(stored-1,1)%*%t(voxel_matrix))[,1:3]
stopifnot(all(volumes$aseg$data[cbind(stored,1)]==
                labels[cbind(match(xyz[,1],mm$x),match(xyz[,2],mm$y),match(xyz[,3],mm$z))]))
# how far the brain reaches along each axis, in mm, and its tissues: how many cubes of each and how
# bright they are on the scan
cubes&lt;-which(labels&gt;0,arr.ind=TRUE)
extent&lt;-list(x=range(mm$x[cubes[,1]]),y=range(mm$y[cubes[,2]]),z=range(mm$z[cubes[,3]]))
tissue_list&lt;-read.csv(sep="|",colClasses="character",text="code|name|labels|grey
grey|Grey matter|3 42 8 47 10 11 12 13 17 18 26 28 49 50 51 52 53 54 58 60|#7a7a7a
white|White matter|2 41 7 46 77 85 251 252 253 254 255|#c9c9c9
stem|Brain stem|16|#a3a3a3
fluid|Fluid|4 5 14 15 24 43 44 72|#2e2e2e
other|Choroid plexus and vessels|30 31 62 63|#2e2e2e")
label_numbers&lt;-function(x) {
  result&lt;-as.integer(strsplit(x," ")[[1]])
  return(result)
}
tissue_list$volume&lt;-sapply(tissue_list$labels,function(x) sum(labels%in%label_numbers(x))/1000)
tissue_list$brightness&lt;-sapply(tissue_list$labels,
                               function(x) mean(scan[labels%in%label_numbers(x)]))
brightness&lt;-setNames(tissue_list$brightness,tissue_list$code)
cortex_brightness&lt;-mean(scan[labels%in%c(3,42)])</code></pre></div></div>
</details>
</div>
<p>The labels fit the scan: on average, the cubes labeled white matter are brighter (93 on the scan’s scale, on which 0 is black and the brightest cube is 118) than those of the cortex (68), and those of the ventricles are the darkest (41), as on any T1-weighted scan. The brain reaches 140 mm from side to side, 175 mm from front to back and 149 mm from the top down to the brain stem, where the scan ends.</p>
</section>
<section id="the-lobes-of-the-cortex" class="level3">
<h3 class="anchored" data-anchor-id="the-lobes-of-the-cortex">The lobes of the cortex</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4"><pre><code class="language-r"># the Desikan-Killiany atlas gives each point of the surface of fsaverage5's cortex a region, and each
# region a lobe. Each cube labeled cortex (3 on the left, 42 on the right) takes the lobe of the
# nearest point of the surface halfway through the cortex of its hemisphere, found with the k-d tree
# of the FNN package; ggseg.meshes keeps the surface turned a quarter round. The points of no region
# lie on the medial wall, where the hemisphere is cut away from the structures under it
atlas&lt;-ggseg.formats::dk()
atlas_points&lt;-atlas$data$vertices
atlas_lobes&lt;-unique(as.data.frame(atlas$core)[,c("label","lobe")])
lobe&lt;-array(NA_character_,dim(labels))
distance&lt;-c()
for(h in c("lh","rh")) {
  mesh&lt;-ggseg.meshes::get_cortical_mesh(h,"midthickness")
  points&lt;-cbind(-mesh$vertices$y,mesh$vertices$x,mesh$vertices$z)
  region&lt;-rep(NA_character_,nrow(points))
  for(k in grep(paste0("^",h,"_"),atlas_points$label))
    region[atlas_points$vertices[[k]]+1]&lt;-atlas_points$label[k]
  cortex&lt;-which(labels==if(h=="lh") 3 else 42,arr.ind=TRUE)
  nearest&lt;-FNN::get.knnx(points,cbind(mm$x[cortex[,1]],mm$y[cortex[,2]],mm$z[cortex[,3]]),k=1)
  lobe[cortex]&lt;-atlas_lobes$lobe[match(region[nearest$nn.index[,1]],atlas_lobes$label)]
  distance&lt;-c(distance,nearest$nn.dist[,1])
}
# the lobes; the atlas also has a region of white matter (its "corpus callosum"), which is no lobe
lobes&lt;-c(frontal="Frontal lobe",parietal="Parietal lobe",temporal="Temporal lobe",
         occipital="Occipital lobe",cingulate="Cingulate gyrus",insula="Insula")
lobe[!lobe%in%names(lobes)]&lt;-NA
with_lobe&lt;-100*mean(!is.na(lobe[labels%in%c(3,42)]))
# how far each lobe reaches along an axis: its least and its greatest coordinate, in mm
lobe_cubes&lt;-which(!is.na(lobe),arr.ind=TRUE)
lobe_of_cube&lt;-lobe[lobe_cubes]
lobe_reach&lt;-function(axis) {
  coordinate&lt;-mm[[axis]][lobe_cubes[,match(axis,c("x","y","z"))]]
  result&lt;-sapply(names(lobes),function(l) range(coordinate[lobe_of_cube==l]))
  return(result)
}
# the lobes whose cortex reaches beyond a coordinate (above it if "above", below it otherwise)
lobes_beyond&lt;-function(axis,coordinate,above) {
  reach&lt;-lobe_reach(axis)
  found&lt;-if(above) reach[2,]&gt;coordinate else reach[1,]&lt;coordinate
  result&lt;-names(lobes)[found]
  return(result)
}</code></pre></div></div>
</details>
</div>
<p>98% of the cubes of cortex get a lobe; the others lie by the medial wall. Half of all the cubes of cortex lie within 2.0 mm of the point of the surface whose lobe they take, and 96% within 5 mm.</p>
</section>
<section id="the-parts-named-on-the-movies" class="level3">
<h3 class="anchored" data-anchor-id="the-parts-named-on-the-movies">The parts named on the movies</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5"><pre><code class="language-r"># the structures under the cortex, colored on the movies: their names, labels and colors. Each pair
# that touches in the volume is told apart also by readers who do not tell red from green (checked
# with a color-vision validator), and the list beside each movie names them
deep_list&lt;-read.csv(sep="|",colClasses="character",text="code|name|labels|colour
caudate|Caudate nucleus|11 50|#e24d8b
putamen|Putamen|12 51|#338ced
pallidum|Globus pallidus|13 52|#eb6263
accumbens|Nucleus accumbens|26 58|#0aac23
thalamus|Thalamus|10 49|#d28e05
ventraldc|Ventral diencephalon|28 60|#9887ef
hippocampus|Hippocampus|17 53|#00a888
amygdala|Amygdala|18 54|#e76624")
# the parts named on the movies but not colored, and the least area of a part, in mm², that a
# section must cut to show its name
named_list&lt;-read.csv(sep="|",colClasses="character",text="code|name|labels|smallest
lateral|Lateral ventricle|4 5 43 44|40
third|Third ventricle|14|12
fourth|Fourth ventricle|15|12
callosum|Corpus callosum|251 252 253 254 255|12
cerebellum|Cerebellum|7 8 46 47|40
brainstem|Brain stem|16|40")
# from a label (0 to 255) to the code of its structure, its named part and its tissue
label_lookup&lt;-function(table) {
  result&lt;-rep(NA_character_,256)
  for(k in seq_len(nrow(table)))
    result[label_numbers(table$labels[k])+1]&lt;-table$code[k]
  return(result)
}
deep_of&lt;-label_lookup(deep_list)
named_of&lt;-label_lookup(named_list)
tissue_of&lt;-label_lookup(tissue_list)
# FreeSurfer's labels of the left and of the right hemisphere; the others lie in the middle
left_labels&lt;-c(2:5,7,8,10:13,17,18,26,28,30,31)
right_labels&lt;-c(41:44,46,47,49:54,58,60,62,63)</code></pre></div></div>
</details>
</div>
</section>
<section id="a-section" class="level3">
<h3 class="anchored" data-anchor-id="a-section">A section</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6"><pre><code class="language-r"># the pictures show the brain with 3 mm to spare. Each plane: the axis that it cuts, the axis that
# runs across its picture and the one that runs up it. A sagittal section is seen from the left,
# with the front of the brain on the left of the picture (flip)
crop&lt;-lapply(extent,function(r) r+c(-3,3))
planes&lt;-list(sagittal=list(cut="x",across="y",up="z",flip=TRUE),
             coronal=list(cut="y",across="x",up="z",flip=FALSE),
             transverse=list(cut="z",across="x",up="y",flip=FALSE))
# where a coordinate falls across a picture, in mm from its left edge
across_of&lt;-function(p,coordinate) {
  result&lt;-coordinate-crop[[p$across]][1]
  if(p$flip)
    result&lt;-diff(crop[[p$across]])-result
  return(result)
}
# a section as a table of its cubes: h across and v up the picture, in mm from its corner, and the
# brightness, the label, the side, the lobe, the structure, the named part and the tissue of each
section&lt;-function(plane,position) {
  p&lt;-planes[[plane]]
  across&lt;-which(mm[[p$across]]&gt;=crop[[p$across]][1]&amp;mm[[p$across]]&lt;=crop[[p$across]][2])
  up&lt;-which(mm[[p$up]]&gt;=crop[[p$up]][1]&amp;mm[[p$up]]&lt;=crop[[p$up]][2])
  grid&lt;-expand.grid(across=across,up=up)
  index&lt;-matrix(0L,nrow(grid),3,dimnames=list(NULL,c("x","y","z")))
  index[,p$cut]&lt;-match(position,mm[[p$cut]])
  index[,p$across]&lt;-grid$across
  index[,p$up]&lt;-grid$up
  label&lt;-labels[index]
  result&lt;-data.frame(h=across_of(p,mm[[p$across]][grid$across]),
                     v=mm[[p$up]][grid$up]-crop[[p$up]][1],brightness=scan[index],label=label,
                     side=ifelse(label%in%left_labels,"left",
                                 ifelse(label%in%right_labels,"right","middle")),
                     lobe=lobe[index],deep=deep_of[label+1],named=named_of[label+1],
                     tissue=tissue_of[label+1])
  return(result)
}
# where a name goes: the cube of the part nearest to its center, if the section cuts enough of it
anchor&lt;-function(cubes,smallest) {
  if(nrow(cubes)&lt;smallest)
    return(NULL)
  centre&lt;-c(mean(cubes$h),mean(cubes$v))
  k&lt;-which.min((cubes$h-centre[1])^2+(cubes$v-centre[2])^2)
  result&lt;-data.frame(h=cubes$h[k],v=cubes$v[k])
  return(result)
}
# the names on a section: the lobes on the left hemisphere (on a sagittal section, on the hemisphere
# that it cuts), the other parts on the right hemisphere or in the middle, so that fewer names crowd
# together
name_tags&lt;-function(s,plane) {
  tags&lt;-list()
  for(l in names(lobes)) {
    cubes&lt;-s[!is.na(s$lobe)&amp;s$lobe==l&amp;(plane=="sagittal"|s$side=="left"),]
    a&lt;-anchor(cubes,if(l=="insula") 25 else 120)
    if(!is.null(a))
      tags[[length(tags)+1]]&lt;-cbind(a,text=lobes[[l]])
  }
  for(k in seq_len(nrow(named_list))) {
    cubes&lt;-s[!is.na(s$named)&amp;s$named==named_list$code[k]&amp;(plane=="sagittal"|s$side!="left"),]
    a&lt;-anchor(cubes,as.numeric(named_list$smallest[k]))
    if(!is.null(a))
      tags[[length(tags)+1]]&lt;-cbind(a,text=named_list$name[k])
  }
  result&lt;-do.call(rbind,tags)
  return(result)
}
# the outline of the brain seen across a plane, for the small brain beside each movie: every line of
# cubes along the cut that holds some brain
outline&lt;-function(plane) {
  p&lt;-planes[[plane]]
  seen&lt;-apply(labels&gt;0,match(c(p$across,p$up),c("x","y","z")),any)
  cells&lt;-which(seen,arr.ind=TRUE)
  result&lt;-data.frame(h=across_of(p,mm[[p$across]][cells[,1]]),
                     v=mm[[p$up]][cells[,2]]-crop[[p$up]][1])
  return(result)
}
# the sagittal movie's small brain is seen from above, the other two from the left
small_plane&lt;-c(sagittal="transverse",coronal="sagittal",transverse="sagittal")
outlines&lt;-lapply(small_plane,outline)</code></pre></div></div>
</details>
</div>
</section>
<section id="a-frame-of-a-movie" class="level3">
<h3 class="anchored" data-anchor-id="a-frame-of-a-movie">A frame of a movie</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7"><pre><code class="language-r"># the inks of the movies, on black: text, quieter text, the structures that a section does not cut,
# and the line of the cut
ink&lt;-"#efefef"
quiet_ink&lt;-"#9c9c9c"
dim_ink&lt;-"#6e6e6e"
dim_swatch&lt;-"#333333"
cut_colour&lt;-"#ffd84d"
# the scan in gray, from black to white; the brightest cubes (white matter) are white
grey_of&lt;-function(brightness) {
  level&lt;-pmin(brightness/105,1)
  result&lt;-rgb(level,level,level)
  return(result)
}
# the size of the frames: 2 pixels for each mm of brain, 6 mm between the two pictures, a column of
# 215 pixels on the right for the small brain and the list, and room above for the titles
pixels&lt;-2
gap&lt;-6
column&lt;-215
frame_size&lt;-function(plane) {
  p&lt;-planes[[plane]]
  result&lt;-c(width=round((2*(diff(crop[[p$across]])+1)+gap)*pixels+column+20),
            height=round((diff(crop[[p$up]])+1)*pixels+104))
  return(result)
}
titles&lt;-c(sagittal="Sagittal sections, from the left side to the right",
          coronal="Coronal sections, from the front to the back",
          transverse="Transverse sections, from the bottom to the top")
# where a section is, in words
position_words&lt;-function(plane,position) {
  result&lt;-switch(plane,
    sagittal=if(position==0) "x = 0 mm: the midline" else
      paste0("x = ",signed(position)," mm: ",abs(position)," mm ",
             if(position&lt;0) "left" else "right"," of the midline"),
    coronal=paste0("y = ",signed(position)," mm: ",extent$y[2]-position,
                   " mm behind the front of the brain"),
    transverse=paste0("z = ",signed(position)," mm: ",extent$z[2]-position,
                      " mm below the top of the brain"))
  return(result)
}
# one frame: the scan on the left, the same section on the right with its tissues in grays, its
# structures in color and its parts named, and a column with the small brain, which shows where the
# cut is, and the structures, lit when the section cuts them
frame_plot&lt;-function(plane,position) {
  p&lt;-planes[[plane]]
  width&lt;-diff(crop[[p$across]])+1
  height&lt;-diff(crop[[p$up]])+1
  s&lt;-section(plane,position)
  s$fill&lt;-grey_of(s$brightness)
  parts&lt;-s
  parts$h&lt;-parts$h+width+gap
  parts$fill&lt;-ifelse(is.na(parts$tissue),"#000000",
                     tissue_list$grey[match(parts$tissue,tissue_list$code)])
  coloured&lt;-!is.na(parts$deep)
  parts$fill[coloured]&lt;-deep_list$colour[match(parts$deep[coloured],deep_list$code)]
  tags&lt;-name_tags(parts,plane)
  # the small brain, shrunk into the top of the column, and the line of the cut across it
  left&lt;-2*width+2*gap+4
  room&lt;-column/pixels
  q&lt;-planes[[small_plane[[plane]]]]
  shrink&lt;-min(0.55*room/(diff(crop[[q$across]])+1),0.32*height/(diff(crop[[q$up]])+1))
  bottom&lt;-height-(diff(crop[[q$up]])+1)*shrink
  small&lt;-outlines[[plane]]
  small$h&lt;-left+small$h*shrink
  small$v&lt;-bottom+small$v*shrink
  if(p$cut==q$across) {
    h&lt;-left+across_of(q,position)*shrink
    cut&lt;-data.frame(h=h,h_end=h,v=bottom-2,v_end=height+2)
  } else {
    v&lt;-bottom+(position-crop[[q$up]][1])*shrink
    cut&lt;-data.frame(h=left-2,h_end=left+(diff(crop[[q$across]])+1)*shrink+2,v=v,v_end=v)
  }
  # the list of structures, lit when the section cuts them
  is_cut&lt;-deep_list$code%in%s$deep
  list_rows&lt;-data.frame(h=left+2,v=bottom-10-(seq_len(nrow(deep_list))-1)*18/pixels,
                        name=deep_list$name,swatch=ifelse(is_cut,deep_list$colour,dim_swatch),
                        ink=ifelse(is_cut,ink,dim_ink))
  directions&lt;-if(plane=="sagittal") c("front","back") else c("left","right")
  result&lt;-ggplot()+
    geom_raster(data=s,aes(h,v,fill=fill),interpolate=TRUE)+
    geom_raster(data=parts,aes(h,v,fill=fill))+
    geom_raster(data=small,aes(h,v),fill="#5a5a5a")+
    geom_segment(data=cut,aes(x=h,xend=h_end,y=v,yend=v_end),colour=cut_colour,linewidth=0.9)+
    annotate("text",x=c(0,width+gap),y=height+3,label=c("The scan","What it shows"),hjust=0,
             vjust=0,colour=ink,size=4.3)+
    annotate("text",x=c(0,width,width+gap,2*width+gap),y=-3,label=rep(directions,2),
             hjust=c(0,1,0,1),vjust=1,colour=quiet_ink,size=3.4)+
    geom_point(data=list_rows,aes(h,v,colour=swatch),shape=15,size=4.6)+
    geom_text(data=list_rows,aes(h+4.5,v,label=name,colour=ink),hjust=0,size=3.7)+
    scale_fill_identity()+
    scale_colour_identity()+
    coord_fixed(xlim=c(0,left+room),ylim=c(-9,height+11),expand=FALSE,clip="off")+
    labs(title=titles[[plane]],subtitle=position_words(plane,position))+
    theme_void()+
    theme(plot.background=element_rect(fill="#000000",colour=NA),
          plot.title=element_text(colour=ink,size=15,face="bold",margin=margin(8,0,2,6)),
          plot.subtitle=element_text(colour=quiet_ink,size=12.5,margin=margin(0,0,4,6)),
          plot.margin=margin(0,8,6,4))
  # the names, pushed apart where they would overlap (with the same seed for every frame)
  if(!is.null(tags))
    result&lt;-result+
      ggrepel::geom_label_repel(data=tags,aes(h,v,label=text),colour="#ffffff",fill="#000000b0",
                                size=3.4,label.size=0,label.padding=unit(0.13,"lines"),
                                box.padding=unit(0.08,"lines"),point.size=NA,
                                min.segment.length=Inf,seed=1,force=0.6,max.overlaps=Inf,
                                xlim=c(width+gap,2*width+gap),ylim=c(0,height))
  return(result)
}</code></pre></div></div>
</details>
</div>
</section>
<section id="making-a-movie" class="level3">
<h3 class="anchored" data-anchor-id="making-a-movie">Making a movie</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8"><pre><code class="language-r"># a movie: each section is drawn by ggplot into a png file (ragg), magick puts every frame on one
# palette (the colors of the page and 48 grays, without dithering) and writes the frames as a GIF
# that loops, holding the last section for about a second. A palette of its own for each frame, as
# gifski makes, looks smoother but changes the colors a little from frame to frame and makes the
# GIF about twice as large
greys&lt;-48
movie_palette&lt;-function() {
  level&lt;-round(seq(0,255,length.out=greys))
  colours&lt;-unique(c(deep_list$colour,cut_colour,ink,quiet_ink,dim_ink,dim_swatch,tissue_list$grey,
                    "#5a5a5a",rgb(level,level,level,maxColorValue=255)))
  result&lt;-image_read(as.raster(matrix(colours,nrow=1)))
  return(result)
}
movie&lt;-function(plane,positions,file,delay=15,hold=7) {
  size&lt;-frame_size(plane)
  frames&lt;-file.path(tempdir(),sprintf("%s_%03d.png",plane,seq_along(positions)))
  on.exit(unlink(frames))
  for(k in seq_along(positions)) {
    ragg::agg_png(frames[k],width=size[["width"]],height=size[["height"]],res=96,
                  background="#000000")
    # the png file is closed even if a frame fails, so that later plots do not go into it
    tryCatch(print(frame_plot(plane,positions[k])),finally=dev.off())
  }
  images&lt;-image_read(c(frames,rep(frames[length(frames)],hold)))
  gif&lt;-image_animate(image_map(images,movie_palette(),dither=FALSE),delay=delay,optimize=TRUE)
  image_write(gif,file)
  return(file)
}
# the file of a movie: in the folder of the page's figures when the page is rendered, so that it is
# published with them, or a temporary file when the code is run by hand
gif_file&lt;-function() {
  result&lt;-if(isTRUE(getOption("knitr.in.progress"))) knitr::fig_path(".gif") else
    tempfile(fileext=".gif")
  dir.create(dirname(result),recursive=TRUE,showWarnings=FALSE)
  return(result)
}
# the sections of a movie: every 3 mm through the brain, at whole multiples of 3 mm, so that the
# sagittal movie passes through the midline
positions_of&lt;-function(axis) {
  result&lt;-seq(3*ceiling(extent[[axis]][1]/3),3*floor(extent[[axis]][2]/3),by=3)
  return(result)
}</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9"><pre><code class="language-r"># the charts on black, like the movies; the source of a chart goes in its caption
knitr::opts_chunk$set(dev.args=list(bg="#000000"))
dark_theme&lt;-theme_minimal(base_size=11)+
  theme(plot.background=element_rect(fill="#000000",colour=NA),
        panel.grid.major=element_line(colour="#303030",linewidth=0.3),
        panel.grid.minor=element_blank(),
        axis.text=element_text(colour=quiet_ink),
        axis.title=element_text(colour=quiet_ink),
        plot.title=element_text(colour=ink,face="bold"),
        plot.subtitle=element_text(colour=quiet_ink),
        plot.caption=element_text(colour=quiet_ink,hjust=0,size=8.5),
        plot.title.position="plot",
        plot.caption.position="plot")
source_note&lt;-"Source: MNI305 and its labels in FreeSurfer's fsaverage (brain.mgz, aseg.mgz)."</code></pre></div></div>
</details>
</div>
<hr>
</section>
</section>
<section id="how-is-the-brain-cut" class="level2">
<h2 class="anchored" data-anchor-id="how-is-the-brain-cut">1. How is the brain cut?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10"><pre><code class="language-r"># the point where the three cuts meet: the middle of the left putamen
middle&lt;-colMeans(which(labels==12,arr.ind=TRUE))
point&lt;-c(x=mm$x[round(middle[1])],y=mm$y[round(middle[2])],z=mm$z[round(middle[3])])
# the area of brain on the largest section in each plane, in cm²
largest_section&lt;-function(axis) {
  counts&lt;-table(factor(mm[[axis]][cubes[,match(axis,c("x","y","z"))]],levels=mm[[axis]]))
  result&lt;-list(position=as.numeric(names(counts)[which.max(counts)]),area=max(counts)/100)
  return(result)
}
largest&lt;-lapply(c(sagittal="x",coronal="y",transverse="z"),largest_section)</code></pre></div></div>
</details>
</div>
<p><strong>In three planes at right angles.</strong> A <strong>sagittal</strong> cut divides left from right, a <strong>coronal</strong> cut front from back, and a <strong>transverse</strong> cut top from bottom. Below, the three cut through one point, the middle of the left putamen, at x = −26, y = 0 and z = −2 mm: each line marks where the other two cuts pass. The brain is longest from front to back, so the sagittal and the transverse sections, which both run from its front to its back, are larger than the coronal ones: the largest section in each plane covers 153 cm² (sagittal, x = +13), 133 cm² (coronal, y = −50) and 174 cm² (transverse, z = +8).</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11"><pre><code class="language-r"># the colors of the three planes, told apart by color-blind readers too (checked)
plane_colours&lt;-c(sagittal="#338ced",coronal="#e76624",transverse="#00a888")
plane_names&lt;-c(sagittal="Sagittal",coronal="Coronal",transverse="Transverse")
seen_from&lt;-c(sagittal="seen from the left",coronal="seen from behind",
             transverse="seen from above")
pictures&lt;-data.frame()
cut_lines&lt;-data.frame()
captions&lt;-data.frame()
offset&lt;-0
for(plane in names(planes)) {
  p&lt;-planes[[plane]]
  s&lt;-section(plane,point[[p$cut]])
  width&lt;-diff(crop[[p$across]])+1
  s$h&lt;-s$h+offset
  s$fill&lt;-grey_of(s$brightness)
  pictures&lt;-rbind(pictures,s[,c("h","v","fill")])
  # the other two planes: a line across this picture where each cuts it
  for(other in setdiff(names(planes),plane)) {
    axis&lt;-planes[[other]]$cut
    if(axis==p$across) {
      h&lt;-offset+across_of(p,point[[axis]])
      cut_lines&lt;-rbind(cut_lines,data.frame(h=h,h_end=h,v=0,v_end=diff(crop[[p$up]])+1,
                                            colour=plane_colours[[other]]))
    } else {
      v&lt;-point[[axis]]-crop[[p$up]][1]
      cut_lines&lt;-rbind(cut_lines,data.frame(h=offset,h_end=offset+width,v=v,v_end=v,
                                            colour=plane_colours[[other]]))
    }
  }
  captions&lt;-rbind(captions,data.frame(h=offset,v=-6,
                                      text=paste0(plane_names[[plane]],", ",seen_from[[plane]]),
                                      position=paste0(p$cut," = ",signed(point[[p$cut]])," mm"),
                                      colour=plane_colours[[plane]]))
  offset&lt;-offset+width+10
}
ggplot()+
  geom_raster(data=pictures,aes(h,v,fill=fill),interpolate=TRUE)+
  geom_segment(data=cut_lines,aes(x=h,xend=h_end,y=v,yend=v_end,colour=colour),linewidth=0.7)+
  geom_segment(data=captions,aes(x=h,xend=h+8,y=v,yend=v,colour=colour),linewidth=2.2)+
  geom_text(data=captions,aes(h+11,v,label=text),hjust=0,colour=ink,size=3.3)+
  geom_text(data=captions,aes(h+11,v-9,label=position),hjust=0,colour=quiet_ink,size=3)+
  scale_fill_identity()+
  scale_colour_identity()+
  coord_fixed(ylim=c(-20,max(pictures$v)+2),expand=FALSE,clip="off")+
  labs(title="One point of the brain, cut in the three planes",caption=source_note)+
  dark_theme+
  theme(axis.text=element_blank(),axis.title=element_blank(),panel.grid.major=element_blank())</code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_SECTIONS_files/figure-html/planes-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><img src="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_SECTIONS_files/figure-html/planes-1.png" class="img-fluid figure-img" style="width:100.0%" alt="Three MRI sections of the average brain through the middle of the left putamen: a sagittal section seen from the left with the front on the left, a coronal section seen from behind and a transverse section seen from above. Colored lines on each section mark where the other two cuts pass."></a></p>
</figure>
</div>
</div>
</div>
<p>Each plane has its own way of being seen. The sagittal sections on this page are seen from the left, with the front of the brain on the left; the coronal ones from behind and the transverse ones from above, with the brain’s left on the left. The coordinates under each picture are those of the cut: x for a sagittal cut, y for a coronal one and z for a transverse one.</p>
<hr>
</section>
<section id="what-does-a-sagittal-section-show" class="level2">
<h2 class="anchored" data-anchor-id="what-does-a-sagittal-section-show">2. What does a sagittal section show?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12"><pre><code class="language-r">cube_coordinates&lt;-function(numbers,axis) {
  found&lt;-which(array(labels%in%numbers,dim(labels)),arr.ind=TRUE)
  result&lt;-mm[[axis]][found[,match(axis,c("x","y","z"))]]
  return(result)
}
insula_x&lt;-mm$x[which(lobe=="insula",arr.ind=TRUE)[,1]]
insula_in&lt;-c(left=min(insula_x)-extent$x[1],right=extent$x[2]-max(insula_x))
deep_x&lt;-abs(cube_coordinates(unlist(lapply(deep_list$labels,label_numbers)),"x"))
callosum_y&lt;-range(cube_coordinates(251:255,"y"))
callosum_x&lt;-range(cube_coordinates(251:255,"x"))</code></pre></div></div>
</details>
</div>
<p><strong>The lobes from the side, the structures deep inside, and the midline.</strong> The movie cuts the brain every 3 mm from its left side to its right. The first sections graze the outside of the hemisphere; the <strong>insula</strong>, the cortex hidden in the lateral sulcus, appears 24 mm in from the side. Next come the structures deep inside: all eight of them lie within 39 mm of the midline, in the middle 56% of the brain’s width. At the midline, the cut passes between the hemispheres and shows what joins them: the <strong>corpus callosum</strong>, the arch of fibers that crosses between them (79 mm from front to back; FreeSurfer labels only the 6 mm in the middle), the <strong>brain stem</strong> and the <strong>cerebellum</strong>.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13"><pre><code class="language-r">knitr::include_graphics(movie("sagittal",positions_of("x"),gif_file()))</code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_SECTIONS_files/figure-html/sagittal_movie-1.gif" class="lightbox" data-gallery="quarto-lightbox-gallery-2"><img src="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_SECTIONS_files/figure-html/sagittal_movie-1.gif" class="img-fluid figure-img" style="width:100.0%" loading="lazy" alt="Movie of sagittal MRI sections of the average brain, every 3 mm from the left side to the right. On the left the scan in grey; on the right the same section with the cortex in dark grey, the white matter in light grey, the fluid in near black, the eight structures under the cortex in colour, and the lobes, the ventricles, the corpus callosum, the cerebellum and the brain stem named. A small brain seen from above shows where the cut is."></a></p>
</figure>
</div>
</div>
</div>
<p>The list on the right names the colored structures, and lights up those that the section cuts. The names on the picture are those of the lobes and of the parts of the brain that are not colored. At x = 0 itself, the cut runs along the narrow gap between the hemispheres, which FreeSurfer leaves without a label, so the picture on the right shows only the parts that cross the midline; the scan, blurred by the averaging, still shows the inner faces of the hemispheres.</p>
<hr>
</section>
<section id="what-does-a-coronal-section-show" class="level2">
<h2 class="anchored" data-anchor-id="what-does-a-coronal-section-show">3. What does a coronal section show?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14"><pre><code class="language-r"># where the temporal lobes begin, the lobes cut in front of them, and at the back of the brain the
# lobes cut behind the frontal and the temporal lobes
reach_y&lt;-lobe_reach("y")
temporal_front&lt;-reach_y[2,"temporal"]
front_lobes&lt;-lobes_beyond("y",temporal_front,above=TRUE)
back_start&lt;-min(reach_y[1,c("frontal","temporal")])
back_lobes&lt;-lobes_beyond("y",back_start,above=FALSE)
deep_list$front&lt;-sapply(deep_list$labels,function(x) max(cube_coordinates(label_numbers(x),"y")))
deep_list$back&lt;-sapply(deep_list$labels,function(x) min(cube_coordinates(label_numbers(x),"y")))
deep_list$length&lt;-deep_list$front-deep_list$back+1
longest&lt;-deep_list[which.max(deep_list$length),]
hippocampus&lt;-deep_list[deep_list$code=="hippocampus",]
deep_y&lt;-c(max(deep_list$front),min(deep_list$back))</code></pre></div></div>
</details>
</div>
<p><strong>The structures deep in the middle of the brain.</strong> The movie cuts the brain every 3 mm from its front to its back. The temporal lobes appear 46 mm behind the front of the brain; in front of them, the only parts of the cortex of the cerebrum that the sections cut are the frontal lobe, the cingulate gyrus and the insula. The structures under the cortex fill only 69 mm of the brain’s 175, from y = +25 to −43. The <strong>caudate nucleus</strong> reaches furthest from front to back, 50 mm, as it curves back along the lateral ventricle. The <strong>putamen</strong> and the <strong>globus pallidus</strong> lie side by side, and the <strong>hippocampus</strong> runs 36 mm back along the inside of the temporal lobe. In the last 23 mm, behind the frontal and the temporal lobes, the only parts of the cortex of the cerebrum are the parietal lobe and the occipital lobe.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15"><pre><code class="language-r">knitr::include_graphics(movie("coronal",rev(positions_of("y")),gif_file()))</code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_SECTIONS_files/figure-html/coronal_movie-1.gif" class="lightbox" data-gallery="quarto-lightbox-gallery-3"><img src="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_SECTIONS_files/figure-html/coronal_movie-1.gif" class="img-fluid figure-img" style="width:100.0%" loading="lazy" alt="Movie of coronal MRI sections of the average brain, every 3 mm from the front to the back. On the left the scan in grey; on the right the same section with the cortex in dark grey, the white matter in light grey, the fluid in near black, the eight structures under the cortex in colour, and the lobes, the ventricles, the corpus callosum, the cerebellum and the brain stem named. A small brain seen from the left shows where the cut is."></a></p>
</figure>
</div>
</div>
</div>
<p>The coronal plane cuts most of these structures across their length, which runs from front to back, so that a section shows several of them side by side.</p>
<hr>
</section>
<section id="what-does-a-transverse-section-show" class="level2">
<h2 class="anchored" data-anchor-id="what-does-a-transverse-section-show">4. What does a transverse section show?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16"><pre><code class="language-r">cerebellum_top&lt;-max(cube_coordinates(c(7,8,46,47),"z"))
lateral_z&lt;-table(cube_coordinates(c(4,43),"z"))
widest&lt;-as.numeric(names(lateral_z)[which.max(lateral_z)])
# the lobes cut by the top sections, above the temporal and the occipital lobes and the insula
reach_z&lt;-lobe_reach("z")
top_start&lt;-max(reach_z[2,c("temporal","occipital","insula")])
top_lobes&lt;-lobes_beyond("z",top_start,above=TRUE)
# the lowest cube of the cerebrum: everything below it is brain stem, cerebellum or fourth ventricle
cerebrum&lt;-c(2:5,10:14,17,18,24,26,28,30,31,41:44,49:54,58,60,62,63,72,77,85,251:255)
cerebrum_bottom&lt;-min(cube_coordinates(cerebrum,"z"))</code></pre></div></div>
</details>
</div>
<p><strong>From the cerebellum and the brain stem at the bottom to the frontal and parietal lobes at the top.</strong> The movie cuts the brain every 3 mm from the bottom up. The lowest sections cut only the <strong>brain stem</strong> and the <strong>cerebellum</strong>, with the fourth ventricle between them; the cerebrum begins at z = −48, with the bottom of the temporal lobes in front of them. The cerebellum ends 68 mm above the bottom of the scan, at z = −2. Higher up come the structures deep inside and the <strong>lateral ventricles</strong>, whose largest section, at z = +18, covers 20.0 cm²; on this plane they have the shape of a butterfly. In the top 39 mm, the only parts of the cortex of the cerebrum are the frontal lobe, the parietal lobe and the cingulate gyrus.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17"><pre><code class="language-r">knitr::include_graphics(movie("transverse",positions_of("z"),gif_file()))</code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_SECTIONS_files/figure-html/transverse_movie-1.gif" class="lightbox" data-gallery="quarto-lightbox-gallery-4"><img src="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_SECTIONS_files/figure-html/transverse_movie-1.gif" class="img-fluid figure-img" style="width:100.0%" loading="lazy" alt="Movie of transverse MRI sections of the average brain, every 3 mm from the bottom to the top. On the left the scan in grey; on the right the same section with the cortex in dark grey, the white matter in light grey, the fluid in near black, the eight structures under the cortex in colour, and the lobes, the ventricles, the corpus callosum, the cerebellum and the brain stem named. A small brain seen from the left shows where the cut is."></a></p>
</figure>
</div>
</div>
</div>
<p>This is the plane that hospitals call axial, and they usually show it with the brain’s left on the right of the picture, the radiological convention.</p>
<hr>
</section>
<section id="why-does-white-matter-look-white" class="level2">
<h2 class="anchored" data-anchor-id="why-does-white-matter-look-white">5. Why does white matter look white?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18"><pre><code class="language-r"># the brightness of the cubes of each part on the scan: the middle 80% and the median
parts_list&lt;-read.csv(sep="|",colClasses="character",text="name|labels|colour
Cerebral white matter|2 41|#c9c9c9
Corpus callosum|251 252 253 254 255|#c9c9c9
Cerebellar white matter|7 46|#c9c9c9
Brain stem|16|#c9c9c9
Cerebral cortex|3 42|#c9c9c9
Cerebellar cortex|8 47|#c9c9c9
Lateral ventricles|4 5 43 44|#c9c9c9
Third and fourth ventricles|14 15|#c9c9c9")
parts_list&lt;-rbind(parts_list,data.frame(name=deep_list$name,labels=deep_list$labels,
                                        colour=deep_list$colour))
spread&lt;-t(sapply(parts_list$labels,function(x)
  quantile(scan[labels%in%label_numbers(x)],c(0.1,0.5,0.9))))
parts_list&lt;-cbind(parts_list,low=spread[,1],median=spread[,2],high=spread[,3])
parts_list&lt;-parts_list[order(parts_list$median),]
brightest&lt;-parts_list[nrow(parts_list),]
second&lt;-parts_list[nrow(parts_list)-1,]
white_row&lt;-parts_list[parts_list$name=="Cerebral white matter",]
cortex_row&lt;-parts_list[parts_list$name=="Cerebral cortex",]
overlap&lt;-100*mean(scan[labels%in%c(3,42)]&gt;=white_row$low)</code></pre></div></div>
</details>
</div>
<p><strong>Because of myelin.</strong> On a T1-weighted scan, the faster the water in a cube returns to rest after each pulse of the scanner (the shorter its T1), the brighter the cube. The fatty myelin around the fibers of white matter makes this quick, so white matter is bright; the water of the fluid in the ventricles is the slowest, so they are dark, and gray matter lies in between. The contrast between the tissues comes mainly from myelin, and from iron, which shortens T1 too (<a href="https://doi.org/10.1016/j.neuroimage.2014.02.026">Stüber et al.&nbsp;2014</a>; <a href="https://doi.org/10.1016/j.neuroimage.2013.06.005">Lutti et al.&nbsp;2014</a>). On this scan, half of the cubes of white matter are brighter than 93 and half of the cubes of cortex brighter than 69. The brightest part of all is the globus pallidus, 101, whose name means “pale globe” in Latin: many fibres wrapped in myelin run through it, and it holds more iron than any other part of the brain (<a href="https://doi.org/10.1111/j.1471-4159.1958.tb12607.x">Hallgren and Sourander 1958</a>). Next comes the ventral diencephalon, 96: besides its small nuclei, FreeSurfer’s label takes in bundles of white matter that run under the thalamus.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19"><pre><code class="language-r">ggplot(parts_list,aes(y=factor(name,levels=name)))+
  geom_segment(aes(x=low,xend=high,yend=factor(name,levels=name),colour=colour),linewidth=1.6,
               alpha=0.55)+
  geom_point(aes(x=median,colour=colour),size=2.8)+
  scale_colour_identity()+
  scale_x_continuous(limits=c(0,max(scan)),breaks=seq(0,120,by=20))+
  labs(title="How bright each part of the brain is on the scan",
       subtitle="The median of its cubes, and the middle 80% of them (0 is black)",
       x="Brightness on the scan",y=NULL,caption=source_note)+
  dark_theme+
  theme(axis.text.y=element_text(colour=ink))</code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_SECTIONS_files/figure-html/brightness-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-5"><img src="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_SECTIONS_files/figure-html/brightness-1.png" class="img-fluid figure-img" style="width:100.0%" alt="Dot chart of how bright the cubes of each part of the brain are on the scan: the ventricles are darkest, the cortex and the hippocampus in the middle, the white matter bright, and the globus pallidus brightest of all. Each part has a line for the middle 80% of its cubes and a dot for the median."></a></p>
</figure>
</div>
</div>
</div>
<p>The colors are those of the movies. The tissues overlap: 10% of the cubes of cortex are as bright as the darkest tenth of the cubes of white matter, mostly where the two meet and a cube of 1 mm holds some of each. This is why FreeSurfer labels the brain from more than brightness: it also uses where each structure usually lies, and next to what (<a href="https://doi.org/10.1016/S0896-6273(02)00569-X">Fischl et al.&nbsp;2002</a>).</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20"><pre><code class="language-r">brain_volume&lt;-sum(tissue_list$volume)
share&lt;-setNames(100*tissue_list$volume/brain_volume,tissue_list$code)</code></pre></div></div>
</details>
</div>
<p>By the labels, the brain on the scan holds 831 cm³ of gray matter (57%), 550 cm³ of white matter (38%) and 48 cm³ of fluid, almost all of it in its ventricles (3%).</p>
<hr>
</section>
<section id="so-what-does-it-mean" class="level2">
<h2 class="anchored" data-anchor-id="so-what-does-it-mean">So, what does it mean?</h2>
<p><strong>Three cuts at right angles are enough to find any point of the brain, and each shows something best.</strong></p>
<ol type="1">
<li><strong>Sagittal</strong>: the lobes from the side, and at the midline the corpus callosum, the brain stem and the cerebellum. The insula begins about 24 mm in from the side.</li>
<li><strong>Coronal</strong>: the structures deep inside, side by side, within 69 mm of the brain’s 175 from front to back; the caudate nucleus reaches furthest, 50 mm.</li>
<li><strong>Transverse</strong>: the plane that hospitals call axial, from the cerebellum at the bottom, past the butterfly of the lateral ventricles, to the frontal and parietal lobes at the top.</li>
<li><strong>Brightness</strong>: white matter is white because of its myelin; the globus pallidus, crossed by many fibres wrapped in myelin and rich in iron, is the brightest of all; fluid is dark.</li>
</ol>
<p><strong>What this does not show.</strong> The scan is an average of 305 young adults, smoother than any one brain: averaging blurs the folds, so the grooves look shallower and the cortex smoother than in a real scan, and the parts of a real brain differ in size and shape from person to person. The labels are those that FreeSurfer keeps for fsaverage, not a segmentation of any one person’s scan, and the volumes are those of the average brain, whose size is set by the template, not by any one head. The lobes come from the nearest point of an atlas drawn on a surface of the cortex, so they are only approximate at their borders, and the atlas does not name the cortex of the medial wall. The movies keep to 48 grays and the colors of the page, and to one section every 3 mm. The scan ends at the brain stem, which goes on down into the spinal cord.</p>
<p>For the same brain in 3D, its parts, its folds and its wiring, see <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Inside the Human Brain</a>; for the networks of its cortex, <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_NETWORKS.html">The Brain’s Seven Networks</a>.</p>
<hr>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<ul>
<li>Betts, J.G. and others (2022), <a href="https://openstax.org/books/anatomy-and-physiology-2e/pages/1-6-anatomical-terminology">Anatomy and Physiology 2e</a>, section 1.6, Anatomical Terminology, OpenStax: the planes of the body.</li>
<li>Brett, M. and the nibabel developers, <a href="https://nipy.org/nibabel/neuro_radio_conventions.html">Radiological vs neurological conventions</a>, nibabel documentation.</li>
<li>Desikan, R.S. and others (2006), <a href="https://doi.org/10.1016/j.neuroimage.2006.01.021">An automated labeling system for subdividing the human cerebral cortex on MRI scans into gyral based regions of interest</a>, <em>NeuroImage</em> 31, 968–980.</li>
<li>Evans, A.C., Collins, D.L., Mills, S.R., Brown, E.D., Kelly, R.L. and Peters, T.M. (1993), <a href="https://doi.org/10.1109/NSSMIC.1993.373602">3D statistical neuroanatomical models from 305 MRI volumes</a>, <em>IEEE Nuclear Science Symposium and Medical Imaging Conference</em>, 1813–1817: MNI305; see also the <a href="https://nist.mni.mcgill.ca/?p=957">MNI’s page on MNI305</a>.</li>
<li>Fischl, B. and others (2002), <a href="https://doi.org/10.1016/S0896-6273(02)00569-X">Whole brain segmentation: automated labeling of neuroanatomical structures in the human brain</a>, <em>Neuron</em> 33, 341–355: the segmentation.</li>
<li>FreeSurfer, <a href="https://openwetware.org/wiki/Beauchamp:FSAverageReadme">README of fsaverage</a> (a copy of the file that comes with FreeSurfer): its volumes are MNI305, and brain.mgz is MNI305 masked to the brain.</li>
<li>Hallgren, B. and Sourander, P. (1958), <a href="https://doi.org/10.1111/j.1471-4159.1958.tb12607.x">The effect of age on the non-haemin iron in the human brain</a>, <em>Journal of Neurochemistry</em> 3, 41–51: the globus pallidus holds the most iron.</li>
<li>Lutti, A., Dick, F., Sereno, M.I. and Weiskopf, N. (2014), <a href="https://doi.org/10.1016/j.neuroimage.2013.06.005">Using high-resolution quantitative mapping of R1 as an index of cortical myelination</a>, <em>NeuroImage</em> 93, 176–188.</li>
<li>Mowinckel, A.M. and Vidal-Piñeiro, D. (2020), <a href="https://doi.org/10.1177/2515245920928009">Visualization of brain statistics with R packages ggseg and ggseg3d</a>, <em>Advances in Methods and Practices in Psychological Science</em> 3, 466–483; the surfaces and the atlas come from the packages <a href="https://ggsegverse.github.io/ggseg.formats/">ggseg.formats</a> and <a href="https://ggsegverse.github.io/ggseg.meshes/">ggseg.meshes</a>.</li>
<li>Schäfer, T. and Ecker, C. (2020), <a href="https://doi.org/10.1101/2020.09.18.302935">fsbrain: an R package for the visualization of structural neuroimaging data</a>, <em>bioRxiv</em>: its server keeps the copy of fsaverage’s volumes that the page downloads.</li>
<li>Stüber, C. and others (2014), <a href="https://doi.org/10.1016/j.neuroimage.2014.02.026">Myelin and iron concentration in the human brain: a quantitative study of MRI contrast</a>, <em>NeuroImage</em> 93, 95–106.</li>
<li><a href="https://docs.ropensci.org/magick/">magick</a> and <a href="https://ggrepel.slowkow.com/">ggrepel</a>, the R packages that make the GIFs and keep the names apart.</li>
</ul>
<hr>
</section>
<section id="acknowledgments" class="level2">
<h2 class="anchored" data-anchor-id="acknowledgments">Acknowledgments</h2>
<p>The scan is MNI305, made at the Montreal Neurological Institute (<a href="https://doi.org/10.1109/NSSMIC.1993.373602">Evans et al.&nbsp;1993</a>), as <a href="https://surfer.nmr.mgh.harvard.edu/">FreeSurfer</a> keeps it in fsaverage, with its labels; the atlas of the lobes and the surface of the cortex come from the R packages ggseg.formats and ggseg.meshes, © 2026 their authors, under the MIT license, and the copy of the volumes from the server of the fsbrain package. The pictures on this page are modified from FreeSurfer’s files: the volumes are turned round, cut into sections and drawn in grays and colors, and the cortex is divided into lobes; they are not FreeSurfer’s original files.</p>
<p>All or portions of this licensed product (such portions are the “Software”) have been obtained under license from The General Hospital Corporation “MGH” and are subject to the following terms and conditions:</p>
<details>
<summary>
The FreeSurfer Software License Agreement, version 1.0 (February 2011), part B
</summary>
<pre class="text"><code>PART B. DOWNLOADING AGREEMENT - License from MGH with Right to Sublicense
("Software License").
1. As used in this Software License, "you" means the individual
   downloading and/or using, reproducing, modifying, displaying and/or
   distributing the Software and the institution or entity which
   employs or is otherwise affiliated with such individual in
   connection therewith. The General Hospital Corporation ("MGH")
   hereby grants you, with right to sublicense, with
   respect to MGH's rights in the software, and data, if any,
   which is the subject of this Software License (collectively, the
   "Software"), a royalty-free, non-exclusive license to use,
   reproduce, make derivative works of, display and distribute the
   Software, provided that:
(a) you accept and adhere to all of the terms and conditions of this
Software License;
(b) in connection with any copy of or sublicense of all or any portion
of the Software, all of the terms and conditions in this Software
License shall appear in and shall apply to such copy and such
sublicense, including without limitation all source and executable
forms and on any user documentation, prefaced with the following
words: "All or portions of this licensed product (such portions are
the "Software") have been obtained under license from The General Hospital
Corporation "MGH" and are subject to the following terms and
conditions:"
(c) you preserve and maintain all applicable attributions, copyright
notices and licenses included in or applicable to the Software;
(d) modified versions of the Software must be clearly identified and
marked as such, and must not be misrepresented as being the original
Software; and
(e) you consider making, but are under no obligation to make, the
source code of any of your modifications to the Software freely
available to others on an open source basis.
2. The license granted in this Software License includes without
   limitation the right to (i) incorporate the Software into
   proprietary programs (subject to any restrictions applicable to
   such programs), (ii) add your own copyright statement to your
   modifications of the Software, and (iii) provide additional or
   different license terms and conditions in your sublicenses of
   modifications of the Software; provided that in each case your use,
   reproduction or distribution of such modifications otherwise
   complies with the conditions stated in this Software License.
3. This Software License does not grant any rights with respect to
   third party software, except those rights that MGH has been
   authorized by a third party to grant to you, and accordingly you
   are solely responsible for (i) obtaining any permissions from third
   parties that you need to use, reproduce, make derivative works of,
   display and distribute the Software, and (ii) informing your
   sublicensees, including without limitation your end-users, of their
   obligations to secure any such required permissions.
4. The Software has been designed for research purposes only and has
   not been reviewed or approved by the Food and Drug Administration
   or by any other agency. YOU ACKNOWLEDGE AND AGREE THAT CLINICAL
   APPLICATIONS ARE NEITHER RECOMMENDED NOR ADVISED. Any
   commercialization of the Software is at the sole risk of the party
   or parties engaged in such commercialization. You further agree to
   use, reproduce, make derivative works of, display and distribute
   the Software in compliance with all applicable governmental laws,
   regulations and orders, including without limitation those relating
   to export and import control.
5. The Software is provided "AS IS" and neither MGH nor any
   contributor to the software (each a "Contributor") shall have any
   obligation to provide maintenance, support, updates, enhancements
   or modifications thereto. MGH AND ALL CONTRIBUTORS SPECIFICALLY
   DISCLAIM ALL EXPRESS AND IMPLIED WARRANTIES OF ANY KIND INCLUDING,
   BUT NOT LIMITED TO, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR
   A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
   MGH OR ANY CONTRIBUTOR BE LIABLE TO ANY PARTY FOR DIRECT,
   INDIRECT, SPECIAL, INCIDENTAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES
   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY ARISING IN ANY WAY
   RELATED TO THE SOFTWARE, EVEN IF MGH OR ANY CONTRIBUTOR HAS
   BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. TO THE MAXIMUM
   EXTENT NOT PROHIBITED BY LAW OR REGULATION, YOU FURTHER ASSUME ALL
   LIABILITY FOR YOUR USE, REPRODUCTION, MAKING OF DERIVATIVE WORKS,
   DISPLAY, LICENSE OR DISTRIBUTION OF THE SOFTWARE AND AGREE TO
   INDEMNIFY AND HOLD HARMLESS MGH AND ALL CONTRIBUTORS FROM AND
   AGAINST ANY AND ALL CLAIMS, SUITS, ACTIONS, DEMANDS AND JUDGMENTS
   ARISING THEREFROM.
6. None of the names, logos or trademarks of MGH or any of
   MGH's affiliates or any of the Contributors, or any funding
   agency, may be used to endorse or promote products produced in
   whole or in part by operation of the Software or derived from or
   based on the Software without specific prior written permission
   from the applicable party.
7. Any use, reproduction or distribution of the Software which is not
   in accordance with this Software License shall automatically revoke
   all rights granted to you under this Software License and render
   Paragraphs 1 and 2 of this Software License null and void.
8. This Software License does not grant any rights in or to any
   intellectual property owned by MGH or any Contributor except
   those rights expressly granted hereunder.</code></pre>
</details>
<p>The whole agreement is on <a href="https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferSoftwareLicense">FreeSurfer’s website</a>.</p>
<hr>
<p><em>Rendered with R 4.6.2 · ggplot2 · magick · ragg · ggrepel · freesurferformats · ggseg.formats · ggseg.meshes · FNN</em></p>
<!-- -->
</section>
<p>This post first appeared on <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_SECTIONS.html">Illustrations in R</a>, with its interactive charts and the full R code.</p>]]></content:encoded>
    </item>
    <item>
      <title>The Brain’s Seven Networks: Which Parts of the Cortex Work Together</title>
      <link>https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_NETWORKS.html</link>
      <guid isPermaLink="true">https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_NETWORKS.html</guid>
      <pubDate>Mon, 30 Nov 2026 14:00:01 +0200</pubDate>
      <category>R</category>
      <category>Illustrations in R</category>
      <description>The seven networks of the human cortex whose parts rise and fall together even at rest, found by Yeo and colleagues in the brain scans of 1,000 young adults and drawn in 3D with plotly on FreeSurfer’s average brain: where each network lies and what it does, how much of the cortex it takes, how many pieces it is made of, which networks are alike and which are opposites, how sure the map is, and how the seven split into seventeen.</description>
      <content:encoded><![CDATA[<p><em>The seven networks of the human cortex whose parts rise and fall together even at rest, found by Yeo and colleagues in the brain scans of 1,000 young adults and drawn in 3D with plotly on FreeSurfer’s average brain: where each network lies and what it does, how much of the cortex it takes, how many pieces it is made of, which networks are alike and which are opposites, how sure the map is, and how the seven split into seventeen.</em></p>
<p><img src="https://sedzinfo.github.io/vignettes/illustration/social-card.png" alt="Illustrations in R" width="1200" height="630"></p>
<section id="what-is-this" class="level2">
<h2 class="anchored" data-anchor-id="what-is-this">What is this?</h2>
<p>Lie still in an MRI scanner with nothing to do, and the brain does not go quiet. Its parts keep working, and parts far apart rise and fall together, as if they kept in touch (<a href="https://doi.org/10.1002/mrm.1910340409">Biswal et al.&nbsp;1995</a>). Parts that keep time this way form <strong>networks</strong>. Yeo and colleagues measured this in 1,000 healthy young adults and divided the cortex into seven networks, and more finely into seventeen (<a href="https://doi.org/10.1152/jn.00338.2011">Yeo et al.&nbsp;2011</a>). This data story draws them on the same average brain as <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Inside the Human Brain</a>, with the same tools. Six questions:</p>
<ol type="1">
<li><strong>Where are the seven networks?</strong></li>
<li><strong>How much of the cortex does each take?</strong></li>
<li><strong>Is each network one piece?</strong></li>
<li><strong>Which networks are alike?</strong></li>
<li><strong>How sure is the map?</strong></li>
<li><strong>Seven or seventeen?</strong></li>
</ol>
<p>The networks come from the repository of Yeo’s lab on GitHub (<a href="https://github.com/ThomasYeoLab/CBIG">CBIG</a>), under the MIT license. For each of the 10,242 points of each hemisphere of <strong>fsaverage5</strong>, FreeSurfer’s average brain, its files give the network of the point among seven and among seventeen, how surely it belongs there, and how strong the scanner’s signal was there. The page downloads the six files, 0.6 MB in all, once. The brain and the Desikan–Killiany atlas of its regions and lobes come with the R packages ggseg.meshes and ggseg.formats, as on <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Inside the Human Brain</a>.</p>
<p><strong>The words of this page:</strong></p>
<ul>
<li><strong>functional MRI</strong> (fMRI) measures, every few seconds, the oxygen in the blood of each small part of the brain, which rises a few seconds after the nerve cells there get busier;</li>
<li><strong>at rest</strong>: lying still in the scanner, awake, with nothing to do;</li>
<li><strong>functional connectivity</strong>: how closely the signals of two places rise and fall together over time, their correlation. Two places can be connected in this way without a tract of white matter between them, through others;</li>
<li>a <strong>network</strong>: places whose connectivity with the whole cortex follows the same pattern. Yeo’s team took, for each point of the cortex, its correlation with 1,175 points spread over the cortex, and sorted the points into groups with similar patterns: once into seven groups, once into seventeen;</li>
<li>the <strong>silhouette</strong> of a point: how much better its own network fits it than the next best one, from −1 to 1. Near 0, the point lies between two networks (<a href="https://doi.org/10.1016/0377-0427(87)90125-7">Rousseeuw 1987</a>).</li>
</ul>
<hr>
</section>
<section id="packages" class="level2">
<h2 class="anchored" data-anchor-id="packages">Packages</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1"><pre><code class="language-r"># install.packages(c("plotly","ggseg.formats","ggseg.meshes","R.matlab"))
library(plotly)</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2"><pre><code class="language-r"># short labels of numbers and lists for the text
number&lt;-function(x) {
  result&lt;-format(round(x),big.mark=",",trim=TRUE)
  return(result)
}
one&lt;-function(x) {
  result&lt;-format(round(x,1),nsmall=1,trim=TRUE)
  return(result)
}
# a correlation or a silhouette, to two decimals, with a minus sign rather than a hyphen
two&lt;-function(x) {
  result&lt;-sub("^-","−",format(round(x,2),nsmall=2,trim=TRUE))
  return(result)
}
percent&lt;-function(x) {
  result&lt;-paste0(round(x),"%")
  return(result)
}
and_list&lt;-function(x) {
  result&lt;-if(length(x)&lt;2) paste(x) else paste(paste(x[-length(x)],collapse=", "),"and",
                                               x[length(x)])
  return(result)
}
count_words&lt;-function(n) {
  words&lt;-c("one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve")
  result&lt;-if(n&lt;=12) words[n] else number(n)
  return(result)
}
upper_first&lt;-function(x) {
  result&lt;-paste0(toupper(substr(x,1,1)),substring(x,2))
  return(result)
}
lower_first&lt;-function(x) {
  result&lt;-paste0(tolower(substr(x,1,1)),substring(x,2))
  return(result)
}</code></pre></div></div>
</details>
</div>
</section>
<section id="the-data" class="level2">
<h2 class="anchored" data-anchor-id="the-data">The data</h2>
<section id="the-cortex" class="level3">
<h3 class="anchored" data-anchor-id="the-cortex">The cortex</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3"><pre><code class="language-r"># a surface of the cortex of one hemisphere of fsaverage5, 10,242 points joined in 20,480 triangles.
# ggseg.meshes keeps it turned a quarter round, with x from the back to the front: here x runs from
# left to right, y from the back to the front and z from the bottom to the top, in mm, as on Inside
# the Human Brain
read_surface&lt;-function(hemisphere,surface) {
  mesh&lt;-ggseg.meshes::get_cortical_mesh(hemisphere,surface)
  vertices&lt;-cbind(x=-mesh$vertices$y,y=mesh$vertices$x,z=mesh$vertices$z)
  result&lt;-list(vertices=vertices,faces=as.matrix(mesh$faces))
  return(result)
}
# the area of each triangle of a surface, in mm²
triangle_area&lt;-function(vertices,faces) {
  a&lt;-vertices[faces[,2],]-vertices[faces[,1],]
  b&lt;-vertices[faces[,3],]-vertices[faces[,1],]
  result&lt;-sqrt((a[,2]*b[,3]-a[,3]*b[,2])^2+(a[,3]*b[,1]-a[,1]*b[,3])^2+
               (a[,1]*b[,2]-a[,2]*b[,1])^2)/2
  return(result)
}
# the Desikan-Killiany atlas: the points of each region (numbered from 0), and the lobe of each
atlas&lt;-ggseg.formats::dk()
atlas_points&lt;-atlas$data$vertices
atlas_lobes&lt;-unique(as.data.frame(atlas$core)[,c("label","lobe")])
hemispheres&lt;-c(lh="left",rh="right")
faces&lt;-list()
points&lt;-data.frame()
for(h in names(hemispheres)) {
  pial&lt;-read_surface(h,"pial")
  middle&lt;-read_surface(h,"midthickness")$vertices
  # the inflated surface comes from ggseg.formats, already in this frame but with each hemisphere
  # around x = 0: they move apart, their inner sides 4 mm from the middle
  inflated&lt;-as.matrix(ggseg.formats::get_brain_mesh(h,"inflated")$vertices)
  inflated[,1]&lt;-if(h=="lh") inflated[,1]-max(inflated[,1])-4 else inflated[,1]-min(inflated[,1])+4
  faces[[h]]&lt;-pial$faces
  # the region of each point; the points of no region, and those that the atlas calls corpus
  # callosum, are the medial wall, where the hemisphere is cut away from the structures under it
  region&lt;-rep("medialwall",nrow(pial$vertices))
  for(k in grep(paste0("^",h,"_"),atlas_points$label))
    region[atlas_points$vertices[[k]]+1]&lt;-sub("^[lr]h_","",atlas_points$label[k])
  region[region=="corpuscallosum"]&lt;-"medialwall"
  # the area of the cortex around each point, measured halfway through its thickness: a third of
  # each triangle that the point is a corner of
  area&lt;-as.vector(rowsum(rep(triangle_area(middle,pial$faces)/3,3),as.vector(pial$faces)))
  points&lt;-rbind(points,data.frame(hemisphere=hemispheres[[h]],region=region,pial$vertices,
                                  inflated_x=inflated[,1],inflated_y=inflated[,2],
                                  inflated_z=inflated[,3],area=area))
}
points$lobe&lt;-atlas_lobes$lobe[match(paste0(substr(points$hemisphere,1,1),"h_",points$region),
                                    atlas_lobes$label)]
xyz&lt;-as.matrix(points[,c("x","y","z")])</code></pre></div></div>
</details>
</div>
</section>
<section id="the-networks" class="level3">
<h3 class="anchored" data-anchor-id="the-networks">The networks</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4"><pre><code class="language-r">download_file&lt;-function(url,file,tries=3) {
  for(k in seq_len(tries)) {
    done&lt;-tryCatch(download.file(url,file,mode="wb",quiet=TRUE)==0,error=function(e) FALSE)
    if(done)
      return(invisible(file))
    Sys.sleep(10)
  }
  stop("Could not download ",url)
}
cache&lt;-tools::R_user_dir("illustration","cache")
dir.create(cache,recursive=TRUE,showWarnings=FALSE)
# the files of the networks, from the repository of Yeo's lab at the commits that last changed them;
# the page keeps its downloads, and the checksums make sure that they are the files the page was
# written for
cbig&lt;-paste0("https://raw.githubusercontent.com/ThomasYeoLab/CBIG/%s/stable_projects/",
             "brain_parcellation/Yeo2011_fcMRI_clustering/1000subjects_reference/%s")
maps_commit&lt;-"ef8e1feba9ee1d7cb8940c4ec27ce3d34941ad62"  # 14 October 2016
names_commit&lt;-"703454dba7b6e0b1cfb97beb449e1593c5170547" # 23 March 2021
yeo_files&lt;-data.frame(
  file=c("1000subjects_clusters007_ref.mat","1000subjects_clusters017_ref.mat",
         "lh.1000subjects.snr.nii.gz","rh.1000subjects.snr.nii.gz","7NetworksOrderedNames.csv",
         "17NetworksOrderedNames.csv"),
  commit=c(rep(maps_commit,4),rep(names_commit,2)),
  md5=c("ab6ce12471152c81083a51e31a294bfb","2c79682024442e9262f7e148d1c795e0",
        "ce375053ee2d4be430cb74e97c9fa10e","578926c5ad4103bb321b6c559f1ef78e",
        "7de3f05a2d2002f1ba56a8d2fc6875b7","775709611220219eb4385f44c2272f00"))
yeo_files$path&lt;-file.path(cache,paste0("yeo2011_",yeo_files$file))
for(k in seq_len(nrow(yeo_files))) {
  if(!file.exists(yeo_files$path[k]))
    download_file(sprintf(cbig,yeo_files$commit[k],yeo_files$file[k]),yeo_files$path[k])
  stopifnot(unname(tools::md5sum(yeo_files$path[k]))==yeo_files$md5[k])
}
# the network of each point among 7 and among 17 (0: none, on the medial wall), and its silhouette
# in the map of 7. R.matlab reads the MATLAB files; each holds both hemispheres
maps&lt;-list(R.matlab::readMat(yeo_files$path[1]),R.matlab::readMat(yeo_files$path[2]))
points$network&lt;-c(maps[[1]]$lh.labels,maps[[1]]$rh.labels)
points$network17&lt;-c(maps[[2]]$lh.labels,maps[[2]]$rh.labels)
points$silhouette&lt;-c(maps[[1]]$lh.s,maps[[1]]$rh.s)
# the signal-to-noise ratio of the scans at each point, averaged over the 1,000 people: a NIfTI file
# of one value per point, 4-byte numbers that start where its header says
read_values&lt;-function(file) {
  connection&lt;-gzfile(file,"rb")
  bytes&lt;-readBin(connection,"raw",1e7)
  close(connection)
  dims&lt;-readBin(bytes[41:56],"integer",8,size=2,endian="little")
  stopifnot(readBin(bytes[71:72],"integer",size=2,endian="little")==16)
  offset&lt;-readBin(bytes[109:112],"numeric",size=4,endian="little")
  result&lt;-readBin(bytes[(offset+1):length(bytes)],"numeric",prod(dims[1+seq_len(dims[1])]),size=4,
                  endian="little")
  return(result)
}
points$snr&lt;-c(read_values(yeo_files$path[3]),read_values(yeo_files$path[4]))
# the names of the networks, in the order of their numbers in the files
names7&lt;-trimws(read.csv(yeo_files$path[5])[[2]])
names17&lt;-trimws(read.csv(yeo_files$path[6])[[2]])
# the networks and the mesh should number their points alike: the points that the atlas puts in the
# cortex should have a network, and those of its medial wall none
in_cortex&lt;-points$region!="medialwall"
with_network&lt;-100*mean(points$network[in_cortex]&gt;0)
wall_without&lt;-100*mean(points$network[!in_cortex]==0)</code></pre></div></div>
</details>
</div>
<p>The networks fit the mesh: 99.9% of the points that the atlas puts in the cortex have a network, and 85% of the points of its medial wall have none. The others lie along the edge of the medial wall, which the two maps draw a little differently.</p>
</section>
<section id="the-networks-and-the-regions" class="level3">
<h3 class="anchored" data-anchor-id="the-networks-and-the-regions">The networks and the regions</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5"><pre><code class="language-r"># the seven networks: what they do, simplified from the studies in the sources
networks&lt;-read.csv(sep="|",text="code|name|role
visual|Visual|Seeing: from the first visual areas to shapes, faces and motion
somatomotor|Somatomotor|Moving and feeling the body, and hearing
dorsal|Dorsal attention|Turning attention to places and things, and moving the eyes
ventral|Salience / ventral attention|Noticing what matters: sudden sounds, pain, the body's feelings
limbic|Limbic|Value and emotion: under the frontal lobe and at the tip of the temporal lobe
control|Control|Keeping a goal in mind, planning, and switching between tasks
default|Default|Busy at rest: remembering, imagining, thinking about oneself and others")
stopifnot(tolower(networks$name)==tolower(names7))
# the names of the regions of the atlas, for the pieces of the networks
regions&lt;-read.csv(sep="|",text="code|name
bankssts|Superior temporal sulcus
caudalanteriorcingulate|Caudal anterior cingulate
caudalmiddlefrontal|Caudal middle frontal gyrus
cuneus|Cuneus
entorhinal|Entorhinal cortex
fusiform|Fusiform gyrus
inferiorparietal|Inferior parietal lobule
inferiortemporal|Inferior temporal gyrus
isthmuscingulate|Isthmus of the cingulate
lateraloccipital|Lateral occipital cortex
lateralorbitofrontal|Lateral orbitofrontal cortex
lingual|Lingual gyrus
medialorbitofrontal|Medial orbitofrontal cortex
middletemporal|Middle temporal gyrus
parahippocampal|Parahippocampal gyrus
paracentral|Paracentral lobule
parsopercularis|Pars opercularis
parsorbitalis|Pars orbitalis
parstriangularis|Pars triangularis
pericalcarine|Pericalcarine cortex
postcentral|Postcentral gyrus
posteriorcingulate|Posterior cingulate
precentral|Precentral gyrus
precuneus|Precuneus
rostralanteriorcingulate|Rostral anterior cingulate
rostralmiddlefrontal|Rostral middle frontal gyrus
superiorfrontal|Superior frontal gyrus
superiorparietal|Superior parietal lobule
superiortemporal|Superior temporal gyrus
supramarginal|Supramarginal gyrus
frontalpole|Frontal pole
temporalpole|Temporal pole
transversetemporal|Transverse temporal gyrus
insula|Insula
medialwall|Medial wall")
lobes&lt;-c(frontal="frontal lobe",parietal="parietal lobe",temporal="temporal lobe",
         occipital="occipital lobe",cingulate="cingulate gyrus",insula="insula")
# the cortex of the networks: every point with a network. A network's area in cm² on each side, and
# its share of the cortex
cortex&lt;-points[points$network&gt;0,]
side_area&lt;-tapply(cortex$area,list(cortex$network,cortex$hemisphere),sum)/100
networks$left&lt;-side_area[,"left"]
networks$right&lt;-side_area[,"right"]
networks$area&lt;-networks$left+networks$right
networks$share&lt;-100*networks$area/sum(networks$area)
# the share of each network's area in each lobe (the few points that the atlas leaves on its medial
# wall have no lobe)
lobe_area&lt;-tapply(cortex$area,list(cortex$network,cortex$lobe),sum)
lobe_area[is.na(lobe_area)]&lt;-0
lobe_share&lt;-100*prop.table(lobe_area[,names(lobes)],1)</code></pre></div></div>
</details>
</div>
</section>
<section id="the-pieces-of-each-network" class="level3">
<h3 class="anchored" data-anchor-id="the-pieces-of-each-network">The pieces of each network</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6"><pre><code class="language-r"># the pieces of a network on one hemisphere: points joined by a side of a triangle, both in that
# network. Every point starts as a piece of its own, numbered by its row; at each round it takes the
# smallest number among its own and its neighbors', and then the number held by the point whose
# number it took, which halves the rounds needed; it stops when nothing changes
pieces_of&lt;-function(network,faces) {
  sides&lt;-rbind(faces[,1:2],faces[,2:3],faces[,c(1,3)])
  sides&lt;-sides[network[sides[,1]]==network[sides[,2]]&amp;network[sides[,1]]&gt;0,,drop=FALSE]
  sides&lt;-rbind(sides,sides[,2:1])
  piece&lt;-seq_along(network)
  repeat {
    smallest&lt;-tapply(piece[sides[,2]],sides[,1],min)
    rows&lt;-as.integer(names(smallest))
    new&lt;-piece
    new[rows]&lt;-pmin(piece[rows],smallest)
    new&lt;-new[new]
    if(all(new==piece))
      break
    piece&lt;-new
  }
  result&lt;-ifelse(network&gt;0,piece,NA)
  return(result)
}
points$piece&lt;-NA
for(h in names(hemispheres)) {
  rows&lt;-which(points$hemisphere==hemispheres[[h]])
  piece&lt;-pieces_of(points$network[rows],faces[[h]])
  points$piece[rows]&lt;-ifelse(is.na(piece),NA,paste(h,piece))
}
cortex&lt;-points[points$network&gt;0,]
# each piece: its hemisphere, its network, its area in cm², and the region that holds most of it. A
# piece counts from 1 cm²; the smaller ones are specks along the borders between networks
piece_area&lt;-tapply(cortex$area,cortex$piece,sum)/100
pieces&lt;-data.frame(piece=names(piece_area),area=as.vector(piece_area))
pieces$hemisphere&lt;-cortex$hemisphere[match(pieces$piece,cortex$piece)]
pieces$network&lt;-cortex$network[match(pieces$piece,cortex$piece)]
region_area&lt;-tapply(cortex$area,list(cortex$piece,cortex$region),sum)
region_area[is.na(region_area)]&lt;-0
main_region&lt;-colnames(region_area)[apply(region_area[pieces$piece,,drop=FALSE],1,which.max)]
pieces$region&lt;-regions$name[match(main_region,regions$code)]
pieces&lt;-pieces[pieces$area&gt;=1,]
pieces&lt;-pieces[order(pieces$network,pieces$hemisphere,-pieces$area),]
piece_count&lt;-table(factor(pieces$network,1:7),factor(pieces$hemisphere,c("left","right")))
# a point at a border: a side of one of its triangles joins it to a point of another network
points$border&lt;-FALSE
for(h in names(hemispheres)) {
  rows&lt;-which(points$hemisphere==hemispheres[[h]])
  network&lt;-points$network[rows]
  sides&lt;-rbind(faces[[h]][,1:2],faces[[h]][,2:3],faces[[h]][,c(1,3)])
  across&lt;-network[sides[,1]]!=network[sides[,2]]&amp;network[sides[,1]]&gt;0&amp;network[sides[,2]]&gt;0
  points$border[rows[unique(as.vector(sides[across,]))]]&lt;-TRUE
}
cortex&lt;-points[points$network&gt;0,]
# a value of each network, averaged over its points and weighted by the area around each point
network_mean&lt;-function(value) {
  result&lt;-as.vector(rowsum(value*cortex$area,cortex$network)/rowsum(cortex$area,cortex$network))
  return(result)
}
networks$silhouette&lt;-network_mean(cortex$silhouette)
networks$unsure&lt;-100*network_mean(cortex$silhouette&lt;0.2)
networks$snr&lt;-network_mean(cortex$snr)</code></pre></div></div>
</details>
</div>
</section>
<section id="how-alike-the-networks-are" class="level3">
<h3 class="anchored" data-anchor-id="how-alike-the-networks-are">How alike the networks are</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7"><pre><code class="language-r"># the clustering that made the networks gives each of them an average profile: how its points
# correlate with the 1,175 points spread over the cortex. Two networks are alike when their profiles
# are, measured by the correlation between the two profiles
profiles&lt;-maps[[1]]$mtc
stopifnot(nrow(profiles)==7)
alike&lt;-cor(t(profiles))
dimnames(alike)&lt;-list(networks$code,networks$code)</code></pre></div></div>
</details>
</div>
</section>
<section id="what-is-drawn" class="level3">
<h3 class="anchored" data-anchor-id="what-is-drawn">What is drawn</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8"><pre><code class="language-r"># the cortex in pieces for the 3D charts, one for each pair of networks (of the 7 and of the 17) on
# each hemisphere, so that a button can color it either way and the pointer can name both: the rows
# of its points in `points`, and its triangles numbered from 0 within the piece. A triangle belongs
# to the networks of its first corner. The pieces of the medial wall come first, then the networks
# in Yeo's order
cut_cortex&lt;-function(key) {
  result&lt;-list()
  for(h in names(hemispheres)) {
    rows&lt;-which(points$hemisphere==hemispheres[[h]])
    corner&lt;-key[rows][faces[[h]][,1]]
    codes&lt;-do.call(rbind,lapply(strsplit(unique(corner)," "),as.integer))
    for(pair in unique(corner)[order(codes[,1],codes[,ncol(codes)])]) {
      triangles&lt;-faces[[h]][corner==pair,,drop=FALSE]
      used&lt;-sort(unique(as.vector(triangles)))
      codes_here&lt;-as.integer(strsplit(pair," ")[[1]])
      result[[length(result)+1]]&lt;-list(hemisphere=hemispheres[[h]],network=codes_here[1],
                                       network17=codes_here[length(codes_here)],rows=rows[used],
                                       faces=matrix(match(triangles,used)-1,ncol=3))
    }
  }
  return(result)
}
shapes&lt;-cut_cortex(paste(points$network,points$network17))
shapes7&lt;-cut_cortex(paste(points$network))</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9"><pre><code class="language-r">dark_gray&lt;-"#6b6b6b" # also the color of the notes and the labels
wall_gray&lt;-"#cdcdcd" # the medial wall, which has no network
# Yeo's colors of the seven networks, from the file, but with the violet of the salience network
# lighter (#BB62FF for #C43AFA) and the gray of the medial wall darker, so that color-blind readers
# can tell every pair apart
network_colours&lt;-setNames(rgb(maps[[1]]$colors[-1,],maxColorValue=255),networks$code)
network_colours[["ventral"]]&lt;-"#BB62FF"
# Yeo's colors of the 17 networks, from the file; with so many, some look alike to color-blind
# readers, and the pointer names each
colours17&lt;-rgb(maps[[2]]$colors[-1,],maxColorValue=255)
# the color scales of the silhouette (pale where the map is unsure) and of the signal-to-noise
# ratio (pale where the signal is weak), and the one of the correlations, blue below 0 and red above
silhouette_scale&lt;-list(list(0,"#fde725"),list(0.25,"#5ec962"),list(0.5,"#21918c"),
                       list(0.75,"#3b528b"),list(1,"#440154"))
snr_scale&lt;-list(list(0,"#deebf7"),list(0.25,"#9ecae1"),list(0.5,"#4292c6"),list(0.75,"#2171b5"),
                list(1,"#08306b"))
correlation_scale&lt;-list(list(0,"#2166ac"),list(0.25,"#92c5de"),list(0.5,"#f7f7f7"),
                        list(0.75,"#f4a582"),list(1,"#b2182b"))
# the source of a chart, as a note under it, and the common layout; note_shift moves the note down
# by a number of pixels, which stays the same however tall the plot is
chart&lt;-function(p,title,source,annotations=list(),margin=list(t=70,b=90),note_y=-0.16,
                note_shift=0,...) {
  note&lt;-list(text=paste("Source:",source),xref="paper",yref="paper",x=0,y=note_y,xanchor="left",
             yanchor="top",yshift=note_shift,align="left",showarrow=FALSE,
             font=list(size=11,color=dark_gray))
  result&lt;-layout(p,
                 title=list(text=title,x=0.02,xanchor="left",y=0.97,yanchor="top"),
                 margin=margin,
                 annotations=c(annotations,list(note)),
                 ...) %&gt;%
    config(displaylogo=FALSE)
  return(result)
}
legend_top&lt;-list(orientation="h",x=0,y=1.02,yanchor="bottom")
yeo&lt;-"Yeo et al. (2011), from the repository of Yeo's lab (CBIG), on FreeSurfer's fsaverage5."
# 3D charts. A mesh of triangles, numbered from 0, in tenths of a mm as whole numbers: plotly for R
# writes any other number with 17 digits, -38.700000000000003 for -38.7. The axes are hidden
tenths&lt;-function(x) {
  result&lt;-round(10*x)
  return(result)
}
add_mesh&lt;-function(p,vertices,faces,name,...) {
  result&lt;-add_trace(p,type="mesh3d",x=tenths(vertices[,1]),y=tenths(vertices[,2]),
                    z=tenths(vertices[,3]),i=faces[,1],j=faces[,2],k=faces[,3],name=name,...)
  return(result)
}
# the last step of a 3D chart: build it, drop its second copy of every number ("attrs"), and give
# each trace its color and its text for the pointer, which plotly for R would leave out (the
# color of a mesh, in whose place it puts a color scale) or repeat for every point (the text); NA
# leaves a trace as it is
finish_3d&lt;-function(p,colours,meta) {
  result&lt;-plotly_build(p)
  result$x$attrs&lt;-NULL
  for(k in seq_along(result$x$data)) {
    if(!is.na(colours[k])) {
      result$x$data[[k]]$color&lt;-colours[[k]]
      result$x$data[[k]]$colorscale&lt;-NULL
    }
    if(!is.na(meta[k])) {
      result$x$data[[k]]$meta&lt;-meta[[k]]
      result$x$data[[k]]$hovertemplate&lt;-"%{meta}&lt;extra&gt;&lt;/extra&gt;"
    }
  }
  return(result)
}
# the light, from above, and the scene: no axes, the brain in its true shape, turned by dragging
lighting&lt;-list(ambient=0.45,diffuse=0.75,specular=0.15,roughness=0.6,fresnel=0.1)
above&lt;-list(x=0,y=0,z=1e5)
scene&lt;-function(eye=list(x=-1.35,y=0.25,z=0.3),domain=list(x=c(0,1),y=c(0,1))) {
  axis&lt;-list(visible=FALSE)
  result&lt;-list(xaxis=axis,yaxis=axis,zaxis=axis,aspectmode="data",dragmode="turntable",
               camera=list(eye=eye),domain=domain)
  return(result)
}
# buttons under a 3D chart that turn the brain to one of six views
views&lt;-list(Left=c(-1.5,0,0.1),Right=c(1.5,0,0.1),Front=c(0,1.5,0.1),Back=c(0,-1.5,0.1),
            Top=c(0,0,1.6),Below=c(0,0,-1.6))
view_buttons&lt;-list()
for(v in names(views)) {
  up&lt;-if(v%in%c("Top","Below")) list(x=0,y=1,z=0) else list(x=0,y=0,z=1)
  eye&lt;-list(x=views[[v]][1],y=views[[v]][2],z=views[[v]][3])
  camera&lt;-list(eye=eye,up=up,center=list(x=0,y=0,z=0))
  view_buttons[[v]]&lt;-list(label=v,method="relayout",args=list(list(scene.camera=camera)))
}
view_menu&lt;-list(type="buttons",direction="right",x=0,y=0,xanchor="left",yanchor="top",
                showactive=FALSE,buttons=unname(view_buttons))
# the text for the pointer: a name in bold, and lines under it
pointer_text&lt;-function(name,...) {
  result&lt;-paste0("&lt;b&gt;",name,"&lt;/b&gt;&lt;br&gt;",paste(...,sep="&lt;br&gt;"))
  return(result)
}
# "one piece" or "five pieces"
piece_words&lt;-function(n) {
  result&lt;-if(n==1) "one piece" else paste(count_words(n),"pieces")
  return(result)
}
# where a network lies: its share in each lobe that holds at least 5% of it, largest first
lobe_words&lt;-function(code) {
  share&lt;-sort(lobe_share[match(code,networks$code),],decreasing=TRUE)
  share&lt;-share[share&gt;=5]
  result&lt;-and_list(paste0(percent(share)," in the ",lobes[names(share)]))
  return(result)
}</code></pre></div></div>
</details>
</div>
<hr>
</section>
</section>
<section id="where-are-the-seven-networks" class="level2">
<h2 class="anchored" data-anchor-id="where-are-the-seven-networks">1. Where are the seven networks?</h2>
<p><strong>Two networks for the senses and movement, five for everything else.</strong> Each network is named after what its parts do together in the studies that first found them:</p>
<ul>
<li><strong>Visual</strong>: seeing, from the first visual areas at the back of the brain to shapes, faces and motion; 63% in the occipital lobe, 19% in the parietal lobe and 17% in the temporal lobe.</li>
<li><strong>Somatomotor</strong>: moving and feeling the body, in a strip on either side of the central sulcus, and hearing; 39% in the parietal lobe, 36% in the frontal lobe and 19% in the temporal lobe.</li>
<li><strong>Dorsal attention</strong>: turning attention to places and things, and moving the eyes towards them (<a href="https://doi.org/10.1038/nrn755">Corbetta and Shulman 2002</a>); 59% in the parietal lobe, 23% in the frontal lobe and 17% in the temporal lobe.</li>
<li><strong>Salience / ventral attention</strong>: noticing what matters, such as a sudden sound, pain or a feeling from inside the body (<a href="https://doi.org/10.1523/JNEUROSCI.5587-06.2007">Seeley et al.&nbsp;2007</a>); 45% in the frontal lobe, 19% in the parietal lobe, 16% in the insula, 11% in the cingulate gyrus and 8% in the temporal lobe.</li>
<li><strong>Limbic</strong>: the value of things and emotion, on the underside of the frontal lobe and at the tip of the temporal lobe; 55% in the temporal lobe and 44% in the frontal lobe.</li>
<li><strong>Control</strong>: keeping a goal in mind, planning, and switching from one task to another (<a href="https://doi.org/10.1152/jn.90355.2008">Vincent et al.&nbsp;2008</a>); 66% in the frontal lobe, 20% in the parietal lobe and 8% in the temporal lobe.</li>
<li><strong>Default</strong>: busy at rest and quieter during most tasks: remembering, imagining the future, and thinking about oneself and others (<a href="https://doi.org/10.1073/pnas.98.2.676">Raichle et al.&nbsp;2001</a>; <a href="https://doi.org/10.1196/annals.1440.011">Buckner et al.&nbsp;2008</a>); 45% in the frontal lobe, 25% in the temporal lobe, 20% in the parietal lobe and 10% in the cingulate gyrus.</li>
</ul>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10"><pre><code class="language-r"># the color of each piece in the map of 7 and in the map of 17, its text for the pointer, and its
# points folded and inflated, for the buttons
p&lt;-plot_ly()
trace7&lt;-c()
trace17&lt;-c()
meta&lt;-c()
inflated&lt;-list(x=list(),y=list(),z=list())
folded&lt;-list(x=list(),y=list(),z=list())
shown&lt;-c()
for(shape in shapes) {
  folded$x[[length(folded$x)+1]]&lt;-tenths(points$x[shape$rows])
  folded$y[[length(folded$y)+1]]&lt;-tenths(points$y[shape$rows])
  folded$z[[length(folded$z)+1]]&lt;-tenths(points$z[shape$rows])
  inflated$x[[length(inflated$x)+1]]&lt;-tenths(points$inflated_x[shape$rows])
  inflated$y[[length(inflated$y)+1]]&lt;-tenths(points$inflated_y[shape$rows])
  inflated$z[[length(inflated$z)+1]]&lt;-tenths(points$inflated_z[shape$rows])
  if(shape$network==0) {
    p&lt;-add_mesh(p,xyz[shape$rows,],shape$faces,"Medial wall",flatshading=FALSE,lighting=lighting,
                lightposition=above,showlegend=FALSE)
    trace7&lt;-c(trace7,wall_gray)
    trace17&lt;-c(trace17,wall_gray)
    wall_text&lt;-"No network: where the hemisphere is cut away from the parts under it"
    meta&lt;-c(meta,pointer_text(paste0("Medial wall, ",shape$hemisphere),wall_text))
  } else {
    network&lt;-networks[shape$network,]
    p&lt;-add_mesh(p,xyz[shape$rows,],shape$faces,network$name,legendgroup=network$code,
                showlegend=!network$code%in%shown,flatshading=FALSE,lighting=lighting,
                lightposition=above)
    shown&lt;-c(shown,network$code)
    trace7&lt;-c(trace7,network_colours[[network$code]])
    trace17&lt;-c(trace17,colours17[shape$network17])
    count&lt;-piece_count[shape$network,shape$hemisphere]
    meta&lt;-c(meta,pointer_text(paste0(network$name," network, ",shape$hemisphere),
                              paste("Of the 17:",names17[shape$network17]),network$role,
                              paste0(number(network[[shape$hemisphere]])," cm² on this side, in ",
                                     piece_words(count)," of at least 1 cm²")))
  }
}
colour_menu&lt;-list(type="buttons",direction="right",x=0,y=1,xanchor="left",yanchor="bottom",
                  buttons=list(list(label="7 networks",method="update",
                                    args=list(list(color=as.list(trace7)),
                                              list(showlegend=TRUE))),
                               list(label="17 networks",method="update",
                                    args=list(list(color=as.list(trace17)),
                                              list(showlegend=FALSE)))))
surface_menu&lt;-list(type="buttons",direction="right",x=1,y=1,xanchor="right",yanchor="bottom",
                   buttons=list(list(label="Folded",method="restyle",args=list(folded)),
                                list(label="Inflated",method="restyle",args=list(inflated))))
p %&gt;%
  chart("The seven networks of the cortex",
        paste(yeo,"Drag to turn, scroll to zoom."),
        margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,
        scene=scene(domain=list(x=c(0,0.8),y=c(0,1))),
        legend=list(x=1,xanchor="right",y=0.9,itemsizing="constant"),
        updatemenus=list(colour_menu,surface_menu,view_menu)) %&gt;%
  finish_3d(trace7,meta)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_NETWORKS.html">Interactive chart: The seven networks of the cortex</a></p>
</div>
</div>
<p>The buttons above the brain color it by the seven networks or by the seventeen of question 6, and show it folded or <strong>inflated</strong>, blown up like a balloon until its folds open out, so that the parts of the networks hidden in the folds come into view. A click on a network in the legend hides it, and a double click shows it alone. The pointer over the cortex names the network, what it does and how large it is on that side.</p>
<hr>
</section>
<section id="how-much-of-the-cortex-does-each-take" class="level2">
<h2 class="anchored" data-anchor-id="how-much-of-the-cortex-does-each-take">2. How much of the cortex does each take?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11"><pre><code class="language-r">total&lt;-sum(networks$area)
wall&lt;-sum(points$area[points$network==0])/100
largest&lt;-networks[which.max(networks$area),]
smallest&lt;-networks[which.min(networks$area),]
senses&lt;-c("visual","somatomotor")
association&lt;-sum(networks$share[!networks$code%in%senses])
networks$ratio&lt;-networks$left/networks$right
more_left&lt;-networks[which.max(networks$ratio),]
more_right&lt;-networks[which.min(networks$ratio),]</code></pre></div></div>
</details>
</div>
<p><strong>The default network is the largest, with 22% of the cortex.</strong> The seven networks cover 1,304 cm² of cortex in the two hemispheres; the medial wall, 120 cm², has none. The two networks of the senses and movement take 36% of it, and the five that serve no one sense 64%: in the human brain these <strong>association networks</strong> take up much more of the cortex than in a monkey’s, and they grew most as the brain grew larger in evolution (<a href="https://doi.org/10.1016/j.tics.2013.09.017">Buckner and Krienen 2013</a>). The smallest network is the dorsal attention one, 9%. The two hemispheres differ most in the default network, which is 37% larger on the left, and in the control network, 36% larger on the right.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12"><pre><code class="language-r">sizes&lt;-networks[order(networks$share),]
p&lt;-plot_ly(sizes,y=~name,x=~round(share,1),type="bar",orientation="h",
           marker=list(color=unname(network_colours[sizes$code]),
                       line=list(color=dark_gray,width=0.5)),
           customdata=~paste0(number(left)," cm² on the left, ",number(right)," on the right"),
           hovertemplate="%{y}: %{x:.1f}% of the cortex&lt;br&gt;%{customdata}&lt;extra&gt;&lt;/extra&gt;")
chart(p,"The share of the cortex in each network, both hemispheres, %",
      paste(yeo,"&lt;br&gt;The area is measured halfway through the cortex."),
      margin=list(t=60,b=80,l=10),note_y=-0.2,xaxis=list(title="",ticksuffix="%"),
      yaxis=list(title="",categoryorder="array",categoryarray=sizes$name,automargin=TRUE))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_NETWORKS.html">Interactive chart: The share of the cortex in each network, both hemispheres, %</a></p>
</div>
</div>
<p>Each bar is the area of a network over the area of all seven; the pointer gives its area on each side.</p>
<hr>
</section>
<section id="is-each-network-one-piece" class="level2">
<h2 class="anchored" data-anchor-id="is-each-network-one-piece">3. Is each network one piece?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13"><pre><code class="language-r">one_piece&lt;-networks$code[piece_count[,"left"]==1&amp;piece_count[,"right"]==1]
counts&lt;-piece_count[,"left"]+piece_count[,"right"]
most&lt;-networks[which.max(counts),]
most_count&lt;-piece_count[which.max(counts),]
default_left&lt;-pieces[pieces$network==match("default",networks$code)&amp;pieces$hemisphere=="left",]</code></pre></div></div>
</details>
</div>
<p><strong>The networks of the senses are one piece in each hemisphere; the others are scattered.</strong> The visual and the somatomotor networks are one piece of at least 1 cm² in each hemisphere. The most scattered is the control network, in eight pieces on the left and seven on the right. The largest pieces of the default network on the left lie mostly in the superior frontal gyrus, middle temporal gyrus, precuneus and inferior parietal lobule: far apart, at the front, on the side and on the inner surface of the brain, and yet they rise and fall together. Bundles of white matter join them, such as the cingulum along the inner surface (<a href="https://doi.org/10.1093/cercor/bhn059">Greicius et al.&nbsp;2009</a>; see question 6 of <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Inside the Human Brain</a>).</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14"><pre><code class="language-r">order_count&lt;-networks$name[order(counts)]
p&lt;-plot_ly()
for(side in c("left","right")) {
  listed&lt;-sapply(seq_len(nrow(networks)),function(k) {
    x&lt;-pieces[pieces$network==k&amp;pieces$hemisphere==side,]
    paste0(x$region," (",number(x$area)," cm²)",collapse="&lt;br&gt;")
  })
  p&lt;-add_bars(p,y=networks$name,x=as.vector(piece_count[,side]),orientation="h",
              name=paste(upper_first(side),"hemisphere"),customdata=listed,
              marker=list(color=if(side=="left") "#4a4a4a" else "#a8a8a8"),
              hovertemplate=paste0("%{y}, ",side,": %{x} pieces, mostly in&lt;br&gt;%{customdata}",
                                   "&lt;extra&gt;&lt;/extra&gt;"))
}
chart(p,"The pieces of each network, at least 1 cm² each",
      paste(yeo,"&lt;br&gt;A piece is named after the region of the Desikan-Killiany atlas",
            "with most of it."),
      barmode="group",legend=legend_top,margin=list(t=90,b=80,l=10),note_y=-0.2,
      xaxis=list(title="",dtick=1),
      yaxis=list(title="",categoryorder="array",categoryarray=order_count,automargin=TRUE))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_NETWORKS.html">Interactive chart: The pieces of each network, at least 1 cm² each</a></p>
</div>
</div>
<p>The pointer over a bar lists the pieces of that network on that side, each named after the region of the atlas that holds most of it. The legend of the first chart shows a network alone with a double click, and its pieces with it.</p>
<hr>
</section>
<section id="which-networks-are-alike" class="level2">
<h2 class="anchored" data-anchor-id="which-networks-are-alike">4. Which networks are alike?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15"><pre><code class="language-r">pairs&lt;-which(upper.tri(alike),arr.ind=TRUE)
values&lt;-alike[pairs]
closest&lt;-pairs[which.max(values),]
farthest&lt;-pairs[which.min(values),]
outward&lt;-c("visual","somatomotor","dorsal","ventral")
default_out&lt;-alike["default",outward]</code></pre></div></div>
</details>
</div>
<p><strong>The default network is the opposite of the networks that face the world.</strong> The most alike are the control and the default networks, whose profiles correlate at 0.38; the most unlike are the somatomotor and the control networks, at −0.50. The default network is unlike all four networks of the senses and of attention, from −0.44 to −0.33: when the visual, somatomotor and attention networks talk with one part of the cortex, the default network tends not to. Its activity falls when attention turns to the world outside, and rises when it turns inwards (<a href="https://doi.org/10.1162/jocn.1997.9.5.648">Shulman et al.&nbsp;1997</a>; <a href="https://doi.org/10.1073/pnas.0504136102">Fox et al.&nbsp;2005</a>).</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16"><pre><code class="language-r">shown_alike&lt;-alike
diag(shown_alike)&lt;-NA
labels&lt;-networks$name
p&lt;-plot_ly(x=labels,y=labels,z=round(shown_alike,2),type="heatmap",colorscale=correlation_scale,
           zmin=-0.6,zmax=0.6,xgap=2,ygap=2,
           text=ifelse(is.na(shown_alike),"",two(shown_alike)),texttemplate="%{text}",
           colorbar=list(title=list(text="Correlation"),len=0.6,thickness=12),
           hovertemplate="%{y} and %{x}: %{text}&lt;extra&gt;&lt;/extra&gt;")
chart(p,"How alike the networks' profiles are",
      paste(yeo,"&lt;br&gt;The correlation between the average profiles of two networks."),
      margin=list(t=60,b=110,l=10),note_y=-0.3,
      xaxis=list(title="",tickangle=-30),yaxis=list(title="",autorange="reversed",automargin=TRUE))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_NETWORKS.html">Interactive chart: How alike the networks&#x27; profiles are</a></p>
</div>
</div>
<p>The profile of a network is how its points, on average, correlate with 1,175 points spread over the cortex. Two networks with alike profiles talk with the same parts of the cortex; two with opposite profiles talk with different parts. The diagonal, each network with itself, is left blank.</p>
<hr>
</section>
<section id="how-sure-is-the-map" class="level2">
<h2 class="anchored" data-anchor-id="how-sure-is-the-map">5. How sure is the map?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17"><pre><code class="language-r">overall&lt;-weighted.mean(cortex$silhouette,cortex$area)
at_border&lt;-weighted.mean(cortex$silhouette[cortex$border],cortex$area[cortex$border])
inside&lt;-weighted.mean(cortex$silhouette[!cortex$border],cortex$area[!cortex$border])
border_share&lt;-100*sum(cortex$area[cortex$border])/sum(cortex$area)
below_zero&lt;-100*sum(cortex$area[cortex$silhouette&lt;0])/sum(cortex$area)
surest&lt;-networks[which.max(networks$silhouette),]
least_sure&lt;-networks[which.min(networks$silhouette),]
weakest&lt;-networks[which.min(networks$snr),]
others&lt;-networks$snr[networks$code!=weakest$code]</code></pre></div></div>
</details>
</div>
<p><strong>Surest inside a network, least sure at its borders.</strong> The silhouette of the points averages 0.40: inside a network 0.47, but 0.13 at its borders, where 23% of the cortex lies. Only 2.0% of the cortex has a silhouette below 0, a better fit with another network than with its own. The surest network is the visual one (0.56 on average), the least sure the control network (0.21), 49% of whose area has a silhouette below 0.2. The <strong>limbic network</strong> lies where the scanner’s signal is weakest: its points have a signal-to-noise ratio of 31 on average, against 66 to 78 for the other networks. The underside of the frontal lobe and the tip of the temporal lobe lie next to the air of the sinuses and of the ear canals, which bends the magnetic field of the scanner and weakens the signal there (<a href="https://doi.org/10.1006/nimg.1997.0289">Ojemann et al.&nbsp;1997</a>): the limbic network may partly be the cortex that the scans could not see well, as Yeo’s team warned.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18"><pre><code class="language-r">silhouette_range&lt;-c(10*floor(quantile(100*cortex$silhouette,0.01)/10),
                    10*ceiling(quantile(100*cortex$silhouette,0.99)/10))
silhouette_ticks&lt;-seq(20*ceiling(silhouette_range[1]/20),20*floor(silhouette_range[2]/20),by=20)
snr_range&lt;-c(10*floor(quantile(cortex$snr,0.01)/10),10*ceiling(quantile(cortex$snr,0.99)/10))
p&lt;-plot_ly()
colours&lt;-c()
meta&lt;-c()
coloured&lt;-c()
silhouette_values&lt;-list()
snr_values&lt;-list()
for(k in seq_along(shapes7)) {
  shape&lt;-shapes7[[k]]
  vertices&lt;-as.matrix(points[shape$rows,c("inflated_x","inflated_y","inflated_z")])
  if(shape$network==0) {
    p&lt;-add_mesh(p,vertices,shape$faces,"Medial wall",flatshading=FALSE,lighting=lighting,
                lightposition=above,showlegend=FALSE)
    colours&lt;-c(colours,wall_gray)
    meta&lt;-c(meta,pointer_text(paste0("Medial wall, ",shape$hemisphere),"No network"))
  } else {
    network&lt;-networks[shape$network,]
    silhouette&lt;-round(100*points$silhouette[shape$rows])
    p&lt;-add_mesh(p,vertices,shape$faces,network$name,intensity=silhouette,
                colorscale=silhouette_scale,cmin=silhouette_range[1],cmax=silhouette_range[2],
                showscale=length(coloured)==0,flatshading=FALSE,
                colorbar=list(title=list(text="Silhouette"),len=0.5,thickness=12,
                              tickmode="array",tickvals=silhouette_ticks,
                              ticktext=two(silhouette_ticks/100)),
                lighting=lighting,lightposition=above,showlegend=FALSE)
    colours&lt;-c(colours,NA)
    meta&lt;-c(meta,pointer_text(paste0(network$name," network, ",shape$hemisphere),
                              paste0("Silhouette ",two(network$silhouette)," on average, ",
                                     percent(network$unsure)," of its area below 0.2"),
                              paste0("Signal-to-noise ratio ",number(network$snr)," on average")))
    coloured&lt;-c(coloured,k)
    silhouette_values[[length(silhouette_values)+1]]&lt;-silhouette
    snr_values[[length(snr_values)+1]]&lt;-round(points$snr[shape$rows])
  }
}
silhouette_button&lt;-list(label="Silhouette",method="restyle",
                        args=list(list(intensity=silhouette_values,
                                       colorscale=list(silhouette_scale),
                                       cmin=silhouette_range[1],cmax=silhouette_range[2],
                                       colorbar.title.text="Silhouette",
                                       colorbar.tickmode="array",
                                       colorbar.tickvals=list(silhouette_ticks),
                                       colorbar.ticktext=list(two(silhouette_ticks/100))),
                                  coloured-1))
snr_button&lt;-list(label="Signal",method="restyle",
                 args=list(list(intensity=snr_values,colorscale=list(snr_scale),cmin=snr_range[1],
                                cmax=snr_range[2],colorbar.title.text="Signal to&lt;br&gt;noise",
                                colorbar.tickmode="auto"),
                           coloured-1))
measure_menu&lt;-list(type="buttons",direction="right",x=0,y=1,xanchor="left",yanchor="bottom",
                   buttons=list(silhouette_button,snr_button))
p %&gt;%
  chart("How sure the map is at each point of the cortex, blown up",
        paste(yeo,"Grey: the medial wall."),
        margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,scene=scene(),
        updatemenus=list(measure_menu,view_menu)) %&gt;%
  finish_3d(colours,meta)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_NETWORKS.html">Interactive chart: How sure the map is at each point of the cortex, blown up</a></p>
</div>
</div>
<p>The cortex is inflated, as with the button of the first chart, so that the whole of it shows. The yellow lines are the borders between networks, where a point fits two networks almost equally well. The button <strong>Signal</strong> colors the cortex by the strength of the scanner’s signal instead. Seen from below (the button <strong>Below</strong>), it is pale under the frontal lobe and at the tip of the temporal lobe, where the limbic network lies.</p>
<hr>
</section>
<section id="seven-or-seventeen" class="level2">
<h2 class="anchored" data-anchor-id="seven-or-seventeen">6. Seven or seventeen?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19"><pre><code class="language-r">flows&lt;-tapply(cortex$area,list(cortex$network,cortex$network17),sum)/100
flows[is.na(flows)]&lt;-0
# the network of the 7 that holds most of each of the 17, and the share of it that lies there
parent&lt;-apply(flows,2,which.max)
inside_parent&lt;-100*apply(flows,2,max)/colSums(flows)
nested&lt;-sum(inside_parent&gt;=90)
# the cortex whose network of the 17 belongs mostly to another network of the 7 than its own
moved&lt;-100*sum(cortex$area[parent[cortex$network17]!=cortex$network])/sum(cortex$area)
children&lt;-function(code) {
  result&lt;-names17[parent==match(code,networks$code)]
  return(result)
}
split_most&lt;-networks[which.max(tabulate(parent,7)),]</code></pre></div></div>
</details>
</div>
<p><strong>Mostly by splitting.</strong> Nine of the 17 networks lie for 90% or more inside one of the seven. The visual network splits into Visual Central (Visual A) and Visual Peripheral (Visual B); the default network into the most, four: Temporal Parietal, Default C, Default A and Default B. The two maps were made separately, though, not one by cutting up the other, so they do not fit exactly: 14% of the cortex belongs to a network of the 17 that lies mostly in another network of the seven than its own.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20"><pre><code class="language-r">links&lt;-which(flows&gt;=1,arr.ind=TRUE)
link_colour&lt;-function(colour,alpha) {
  rgb_values&lt;-col2rgb(colour)
  result&lt;-sprintf("rgba(%d,%d,%d,%.2f)",rgb_values[1],rgb_values[2],rgb_values[3],alpha)
  return(result)
}
p&lt;-plot_ly(type="sankey",orientation="h",arrangement="snap",
           node=list(label=c(networks$name,names17),
                     color=c(unname(network_colours),colours17),pad=12,thickness=16,
                     line=list(color=dark_gray,width=0.5),
                     hovertemplate="%{label}: %{value:.0f} cm²&lt;extra&gt;&lt;/extra&gt;"),
           link=list(source=links[,1]-1,target=6+links[,2],value=round(flows[links],1),
                     color=unname(sapply(network_colours[links[,1]],link_colour,alpha=0.45)),
                     hovertemplate=paste0("%{source.label} to %{target.label}: %{value:.0f} cm²",
                                          "&lt;extra&gt;&lt;/extra&gt;")))
chart(p,"From seven networks to seventeen, cm² of cortex",
      paste(yeo,"Bands under 1 cm² are left out."),
      margin=list(t=60,b=60,l=10,r=10),note_y=-0.04)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_NETWORKS.html">Interactive chart: From seven networks to seventeen, cm² of cortex</a></p>
</div>
</div>
<p>Each band is as wide as the area of cortex that a network of the seven shares with one of the seventeen. The button <strong>17 networks</strong> of the first chart shows the seventeen on the brain.</p>
<hr>
</section>
<section id="so-what-does-it-mean" class="level2">
<h2 class="anchored" data-anchor-id="so-what-does-it-mean">So, what does it mean?</h2>
<p><strong>The cortex works as a handful of networks, most of them spread over the whole brain.</strong></p>
<ol type="1">
<li><strong>Seven networks</strong>: two handle the senses and movement, and the other five, 64% of the cortex, handle no one sense.</li>
<li><strong>The largest</strong>: the default network, 22% of the cortex, busy when we rest, remember and imagine.</li>
<li><strong>Scattered</strong>: the networks of the senses are one piece in each hemisphere, while the control network lies in eight pieces on the left; far-apart pieces still rise and fall together.</li>
<li><strong>Opposites</strong>: the profile of the default network correlates at −0.44 to −0.33 with those of the networks that face the world.</li>
<li><strong>Fuzzy borders</strong>: the map is surest inside a network (silhouette 0.47) and least sure at its borders (0.13); the limbic network lies where the scans saw least well.</li>
</ol>
<p><strong>What this does not show.</strong> The networks are an average of 1,000 young adults. In each person the networks lie a little differently, and studied one person at a time they turn out finer, interleaved like the fingers of two hands (<a href="https://doi.org/10.1016/j.neuron.2017.06.038">Braga and Buckner 2017</a>). Their parts rise and fall together, which does not prove that a tract joins them directly. Seven and seventeen are choices: they were the numbers of networks that came out most stable in Yeo’s analyses, and the networks were found again in the second half of the 1,000 people, but the cortex can be divided more coarsely or more finely. The names of the networks come from what their parts do in tasks studied elsewhere, and what each does is simplified here. Finally, the map is drawn on the 10,242 points of fsaverage5, the average brain with which Yeo’s team made it, and its colors are Yeo’s, but for one.</p>
<p>For the anatomy of the same brain, its regions, the structures under the cortex and the tracts of white matter, see <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Inside the Human Brain</a>.</p>
<hr>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<ul>
<li>Biswal, B., Yetkin, F.Z., Haughton, V.M. and Hyde, J.S. (1995), <a href="https://doi.org/10.1002/mrm.1910340409">Functional connectivity in the motor cortex of resting human brain using echo-planar MRI</a>, <em>Magnetic Resonance in Medicine</em> 34, 537–541.</li>
<li>Braga, R.M. and Buckner, R.L. (2017), <a href="https://doi.org/10.1016/j.neuron.2017.06.038">Parallel interdigitated distributed networks within the individual estimated by intrinsic functional connectivity</a>, <em>Neuron</em> 95, 457–471.</li>
<li>Buckner, R.L., Andrews-Hanna, J.R. and Schacter, D.L. (2008), <a href="https://doi.org/10.1196/annals.1440.011">The brain’s default network: anatomy, function, and relevance to disease</a>, <em>Annals of the New York Academy of Sciences</em> 1124, 1–38.</li>
<li>Buckner, R.L. and Krienen, F.M. (2013), <a href="https://doi.org/10.1016/j.tics.2013.09.017">The evolution of distributed association networks in the human brain</a>, <em>Trends in Cognitive Sciences</em> 17, 648–665.</li>
<li>Computational Brain Imaging Group (CBIG), <a href="https://github.com/ThomasYeoLab/CBIG/tree/master/stable_projects/brain_parcellation/Yeo2011_fcMRI_clustering">Yeo2011_fcMRI_clustering</a>, the repository of Yeo’s lab on GitHub: the files of the networks.</li>
<li>Corbetta, M. and Shulman, G.L. (2002), <a href="https://doi.org/10.1038/nrn755">Control of goal-directed and stimulus-driven attention in the brain</a>, <em>Nature Reviews Neuroscience</em> 3, 201–215.</li>
<li>Desikan, R.S. and others (2006), <a href="https://doi.org/10.1016/j.neuroimage.2006.01.021">An automated labeling system for subdividing the human cerebral cortex on MRI scans into gyral based regions of interest</a>, <em>NeuroImage</em> 31, 968–980.</li>
<li>Fischl, B., Sereno, M.I., Tootell, R.B.H. and Dale, A.M. (1999), <a href="https://doi.org/10.1002/(SICI)1097-0193(1999)8%3A4%3C272%3A%3AAID-HBM10%3E3.0.CO%3B2-4">High-resolution intersubject averaging and a coordinate system for the cortical surface</a>, <em>Human Brain Mapping</em> 8, 272–284: fsaverage.</li>
<li>Fox, M.D.&nbsp;and others (2005), <a href="https://doi.org/10.1073/pnas.0504136102">The human brain is intrinsically organized into dynamic, anticorrelated functional networks</a>, <em>Proceedings of the National Academy of Sciences</em> 102, 9673–9678.</li>
<li>Greicius, M.D., Supekar, K., Menon, V. and Dougherty, R.F. (2009), <a href="https://doi.org/10.1093/cercor/bhn059">Resting-state functional connectivity reflects structural connectivity in the default mode network</a>, <em>Cerebral Cortex</em> 19, 72–78.</li>
<li>Mowinckel, A.M. and Vidal-Piñeiro, D. (2020), <a href="https://doi.org/10.1177/2515245920928009">Visualization of brain statistics with R packages ggseg and ggseg3d</a>, <em>Advances in Methods and Practices in Psychological Science</em> 3, 466–483; the surfaces and the atlas come from the packages <a href="https://ggsegverse.github.io/ggseg.formats/">ggseg.formats</a> and <a href="https://ggsegverse.github.io/ggseg.meshes/">ggseg.meshes</a>.</li>
<li>Ojemann, J.G. and others (1997), <a href="https://doi.org/10.1006/nimg.1997.0289">Anatomic localization and quantitative analysis of gradient refocused echo-planar fMRI susceptibility artifacts</a>, <em>NeuroImage</em> 6, 156–167.</li>
<li>Raichle, M.E. and others (2001), <a href="https://doi.org/10.1073/pnas.98.2.676">A default mode of brain function</a>, <em>Proceedings of the National Academy of Sciences</em> 98, 676–682.</li>
<li>Rousseeuw, P.J. (1987), <a href="https://doi.org/10.1016/0377-0427(87)90125-7">Silhouettes: a graphical aid to the interpretation and validation of cluster analysis</a>, <em>Journal of Computational and Applied Mathematics</em> 20, 53–65.</li>
<li>Seeley, W.W. and others (2007), <a href="https://doi.org/10.1523/JNEUROSCI.5587-06.2007">Dissociable intrinsic connectivity networks for salience processing and executive control</a>, <em>Journal of Neuroscience</em> 27, 2349–2356.</li>
<li>Shulman, G.L. and others (1997), <a href="https://doi.org/10.1162/jocn.1997.9.5.648">Common blood flow changes across visual tasks: II. Decreases in cerebral cortex</a>, <em>Journal of Cognitive Neuroscience</em> 9, 648–663.</li>
<li>Vincent, J.L., Kahn, I., Snyder, A.Z., Raichle, M.E. and Buckner, R.L. (2008), <a href="https://doi.org/10.1152/jn.90355.2008">Evidence for a frontoparietal control system revealed by intrinsic functional connectivity</a>, <em>Journal of Neurophysiology</em> 100, 3328–3342.</li>
<li>Yeo, B.T.T. and others (2011), <a href="https://doi.org/10.1152/jn.00338.2011">The organization of the human cerebral cortex estimated by intrinsic functional connectivity</a>, <em>Journal of Neurophysiology</em> 106, 1125–1165.</li>
</ul>
<hr>
</section>
<section id="acknowledgments" class="level2">
<h2 class="anchored" data-anchor-id="acknowledgments">Acknowledgments</h2>
<p>The networks, their silhouettes and the signal-to-noise ratios come from the repository of the Computational Brain Imaging Group of Thomas Yeo, © 2016 CBIG, under the MIT license below. The page draws them on the surfaces of FreeSurfer’s average brain, fsaverage5, from the R packages ggseg.formats and ggseg.meshes, © 2026 their authors, under the MIT license. The surfaces drawn on this page are modified from FreeSurfer’s: they are turned into one frame and cut into pieces by network; they are not FreeSurfer’s original files. The colors of the networks are Yeo’s, but for the violet of the salience network, which is lighter here.</p>
<details>
<summary>
The MIT license of the CBIG repository
</summary>
<pre class="text"><code>Copyright (c) 2016 Computational Brain Imaging Group (CBIG)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</code></pre>
</details>
<p>All or portions of this licensed product (such portions are the “Software”) have been obtained under license from The General Hospital Corporation “MGH” and are subject to the following terms and conditions:</p>
<details>
<summary>
The FreeSurfer Software License Agreement, version 1.0 (February 2011), part B
</summary>
<pre class="text"><code>PART B. DOWNLOADING AGREEMENT - License from MGH with Right to Sublicense
("Software License").
1. As used in this Software License, "you" means the individual
   downloading and/or using, reproducing, modifying, displaying and/or
   distributing the Software and the institution or entity which
   employs or is otherwise affiliated with such individual in
   connection therewith. The General Hospital Corporation ("MGH")
   hereby grants you, with right to sublicense, with
   respect to MGH's rights in the software, and data, if any,
   which is the subject of this Software License (collectively, the
   "Software"), a royalty-free, non-exclusive license to use,
   reproduce, make derivative works of, display and distribute the
   Software, provided that:
(a) you accept and adhere to all of the terms and conditions of this
Software License;
(b) in connection with any copy of or sublicense of all or any portion
of the Software, all of the terms and conditions in this Software
License shall appear in and shall apply to such copy and such
sublicense, including without limitation all source and executable
forms and on any user documentation, prefaced with the following
words: "All or portions of this licensed product (such portions are
the "Software") have been obtained under license from The General Hospital
Corporation "MGH" and are subject to the following terms and
conditions:"
(c) you preserve and maintain all applicable attributions, copyright
notices and licenses included in or applicable to the Software;
(d) modified versions of the Software must be clearly identified and
marked as such, and must not be misrepresented as being the original
Software; and
(e) you consider making, but are under no obligation to make, the
source code of any of your modifications to the Software freely
available to others on an open source basis.
2. The license granted in this Software License includes without
   limitation the right to (i) incorporate the Software into
   proprietary programs (subject to any restrictions applicable to
   such programs), (ii) add your own copyright statement to your
   modifications of the Software, and (iii) provide additional or
   different license terms and conditions in your sublicenses of
   modifications of the Software; provided that in each case your use,
   reproduction or distribution of such modifications otherwise
   complies with the conditions stated in this Software License.
3. This Software License does not grant any rights with respect to
   third party software, except those rights that MGH has been
   authorized by a third party to grant to you, and accordingly you
   are solely responsible for (i) obtaining any permissions from third
   parties that you need to use, reproduce, make derivative works of,
   display and distribute the Software, and (ii) informing your
   sublicensees, including without limitation your end-users, of their
   obligations to secure any such required permissions.
4. The Software has been designed for research purposes only and has
   not been reviewed or approved by the Food and Drug Administration
   or by any other agency. YOU ACKNOWLEDGE AND AGREE THAT CLINICAL
   APPLICATIONS ARE NEITHER RECOMMENDED NOR ADVISED. Any
   commercialization of the Software is at the sole risk of the party
   or parties engaged in such commercialization. You further agree to
   use, reproduce, make derivative works of, display and distribute
   the Software in compliance with all applicable governmental laws,
   regulations and orders, including without limitation those relating
   to export and import control.
5. The Software is provided "AS IS" and neither MGH nor any
   contributor to the software (each a "Contributor") shall have any
   obligation to provide maintenance, support, updates, enhancements
   or modifications thereto. MGH AND ALL CONTRIBUTORS SPECIFICALLY
   DISCLAIM ALL EXPRESS AND IMPLIED WARRANTIES OF ANY KIND INCLUDING,
   BUT NOT LIMITED TO, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR
   A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
   MGH OR ANY CONTRIBUTOR BE LIABLE TO ANY PARTY FOR DIRECT,
   INDIRECT, SPECIAL, INCIDENTAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES
   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY ARISING IN ANY WAY
   RELATED TO THE SOFTWARE, EVEN IF MGH OR ANY CONTRIBUTOR HAS
   BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. TO THE MAXIMUM
   EXTENT NOT PROHIBITED BY LAW OR REGULATION, YOU FURTHER ASSUME ALL
   LIABILITY FOR YOUR USE, REPRODUCTION, MAKING OF DERIVATIVE WORKS,
   DISPLAY, LICENSE OR DISTRIBUTION OF THE SOFTWARE AND AGREE TO
   INDEMNIFY AND HOLD HARMLESS MGH AND ALL CONTRIBUTORS FROM AND
   AGAINST ANY AND ALL CLAIMS, SUITS, ACTIONS, DEMANDS AND JUDGMENTS
   ARISING THEREFROM.
6. None of the names, logos or trademarks of MGH or any of
   MGH's affiliates or any of the Contributors, or any funding
   agency, may be used to endorse or promote products produced in
   whole or in part by operation of the Software or derived from or
   based on the Software without specific prior written permission
   from the applicable party.
7. Any use, reproduction or distribution of the Software which is not
   in accordance with this Software License shall automatically revoke
   all rights granted to you under this Software License and render
   Paragraphs 1 and 2 of this Software License null and void.
8. This Software License does not grant any rights in or to any
   intellectual property owned by MGH or any Contributor except
   those rights expressly granted hereunder.</code></pre>
</details>
<p>The whole agreement is on <a href="https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferSoftwareLicense">FreeSurfer’s website</a>.</p>
<hr>
<p><em>Rendered with R 4.6.2 · plotly · ggseg.formats · ggseg.meshes · R.matlab</em></p>
<!-- -->
</section>
<p>This post first appeared on <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN_NETWORKS.html">Illustrations in R</a>, with its interactive charts and the full R code.</p>]]></content:encoded>
    </item>
    <item>
      <title>Inside the Human Brain: A 3D Map of Its Parts and Wiring</title>
      <link>https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html</link>
      <guid isPermaLink="true">https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html</guid>
      <pubDate>Sun, 29 Nov 2026 21:00:41 +0200</pubDate>
      <category>R</category>
      <category>Illustrations in R</category>
      <description>The average human brain in 3D, drawn with plotly from FreeSurfer’s fsaverage: the lobes and the 34 regions of the cortex in each hemisphere and what they do, how much of the cortex is hidden in the folds and how thick it is, the structures deep under it, from the thalamus to the cerebellum, the hollows filled with fluid in its middle, and 42 tracts of white matter that wire them together.</description>
      <content:encoded><![CDATA[<p><em>The average human brain in 3D, drawn with plotly from FreeSurfer’s fsaverage: the lobes and the 34 regions of the cortex in each hemisphere and what they do, how much of the cortex is hidden in the folds and how thick it is, the structures deep under it, from the thalamus to the cerebellum, the hollows filled with fluid in its middle, and 42 tracts of white matter that wire them together.</em></p>
<p><img src="https://sedzinfo.github.io/vignettes/illustration/social-card.png" alt="Illustrations in R" width="1200" height="630"></p>
<section id="what-is-this" class="level2">
<h2 class="anchored" data-anchor-id="what-is-this">What is this?</h2>
<p>Plotly’s <a href="https://brain-viewer.plotly.app/">MRI Reconstruction</a> app shows a human brain that turns under the mouse (<a href="https://github.com/plotly/dash-sample-apps/tree/master/apps/dash-brain-viewer">its code</a>). This data story draws such a brain with plotly in R and adds its anatomy: the names of its parts, what each part does, how large it is, and how the parts are wired together. Six questions:</p>
<ol type="1">
<li><strong>What are the parts of the cortex?</strong></li>
<li><strong>How much of the cortex is hidden in the folds?</strong></li>
<li><strong>Where is the cortex thickest?</strong></li>
<li><strong>What lies under the cortex?</strong></li>
<li><strong>What fills the hollows inside the brain?</strong></li>
<li><strong>How are the parts wired together?</strong></li>
</ol>
<p>The brain is <strong>fsaverage</strong>, the average brain of FreeSurfer, a widely used program that measures the cortex on MRI scans: the brains of many adults, laid over each other fold to fold (<a href="https://doi.org/10.1002/(SICI)1097-0193(1999)8%3A4%3C272%3A%3AAID-HBM10%3E3.0.CO%3B2-4">Fischl et al.&nbsp;1999</a>). Its parts come from three sources: the <strong>Desikan–Killiany atlas</strong> of the cortex, with 34 regions in each hemisphere, bounded mostly by the folds (<a href="https://doi.org/10.1016/j.neuroimage.2006.01.021">Desikan et al.&nbsp;2006</a>); FreeSurfer’s <strong>segmentation</strong> of the same brain, a volume of cubes of 1 mm each labeled with the structure it lies in (<a href="https://doi.org/10.1016/S0896-6273(02)00569-X">Fischl et al.&nbsp;2002</a>), from which the page draws the structures under the cortex and the ventricles; and <strong>TRACULA</strong>, an atlas of 42 bundles of white matter traced from diffusion MRI (<a href="https://doi.org/10.3389/fninf.2011.00023">Yendiki et al.&nbsp;2011</a>; <a href="https://doi.org/10.1016/j.neuroimage.2021.118706">Maffei et al.&nbsp;2021</a>). The cortex, its atlas and TRACULA come with the R packages ggseg.meshes and ggseg.formats (<a href="https://doi.org/10.1177/2515245920928009">Mowinckel and Vidal-Piñeiro 2020</a>); the segmentation, 365 KB, is downloaded once from the server of the fsbrain package (<a href="https://doi.org/10.1101/2020.09.18.302935">Schäfer and Ecker 2020</a>).</p>
<p><strong>The words of this page:</strong></p>
<ul>
<li>the <strong>cortex</strong> is the outer layer of the brain: a folded sheet of gray matter a few millimeters thick, made of the bodies of nerve cells. Its ridges are <strong>gyri</strong> (one <em>gyrus</em>), its grooves <strong>sulci</strong> (one <em>sulcus</em>);</li>
<li>the brain has two <strong>hemispheres</strong>, left and right (the brain’s own left and right), and the cortex of each is divided into <strong>lobes</strong>;</li>
<li><strong>white matter</strong> is made of the long fibers of nerve cells, wrapped in a fatty sheath; a <strong>tract</strong> is a bundle of them that links two parts of the brain;</li>
<li>the <strong>ventricles</strong> are the hollows inside the brain, filled with a clear fluid (<em>cerebrospinal fluid</em>) that also bathes the brain and the spinal cord;</li>
<li>the <strong>wrap</strong> is the smallest shape around a hemisphere that has no dents (its <em>convex hull</em>): what a sheet of cling film, pulled tight around it, would cover.</li>
</ul>
<hr>
</section>
<section id="packages" class="level2">
<h2 class="anchored" data-anchor-id="packages">Packages</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1"><pre><code class="language-r"># install.packages(c("plotly","ggseg.formats","ggseg.meshes","freesurferformats","misc3d",
#                    "geometry"))
library(plotly)</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2"><pre><code class="language-r"># short labels of numbers, lists and shifts for the text
number&lt;-function(x) {
  result&lt;-format(round(x),big.mark=",",trim=TRUE)
  return(result)
}
one&lt;-function(x) {
  result&lt;-format(round(x,1),nsmall=1,trim=TRUE)
  return(result)
}
percent&lt;-function(x) {
  result&lt;-paste0(round(x),"%")
  return(result)
}
and_list&lt;-function(x) {
  result&lt;-if(length(x)&lt;2) paste(x) else paste(paste(x[-length(x)],collapse=", "),"and",
                                               x[length(x)])
  return(result)
}
count_words&lt;-function(n) {
  words&lt;-c("one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve")
  result&lt;-if(n&lt;=12) words[n] else number(n)
  return(result)
}
upper_first&lt;-function(x) {
  result&lt;-paste0(toupper(substr(x,1,1)),substring(x,2))
  return(result)
}
lower_first&lt;-function(x) {
  result&lt;-paste0(tolower(substr(x,1,1)),substring(x,2))
  return(result)
}
# "24.0 mm further forward" or "3.5 mm further back"
shift_words&lt;-function(x,positive,negative) {
  result&lt;-paste(one(abs(x)),"mm",if(x&gt;=0) positive else negative)
  return(result)
}</code></pre></div></div>
</details>
</div>
</section>
<section id="the-data" class="level2">
<h2 class="anchored" data-anchor-id="the-data">The data</h2>
<section id="the-cortex" class="level3">
<h3 class="anchored" data-anchor-id="the-cortex">The cortex</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3"><pre><code class="language-r"># a surface of the cortex of one hemisphere of fsaverage5, 10,242 points joined in 20,480 triangles.
# ggseg.meshes keeps it turned a quarter round, with x from the back to the front: here x runs from
# left to right, y from the back to the front and z from the bottom to the top, in mm
read_surface&lt;-function(hemisphere,surface) {
  mesh&lt;-ggseg.meshes::get_cortical_mesh(hemisphere,surface)
  vertices&lt;-cbind(x=-mesh$vertices$y,y=mesh$vertices$x,z=mesh$vertices$z)
  result&lt;-list(vertices=vertices,faces=as.matrix(mesh$faces))
  return(result)
}
# the area of each triangle of a surface, in mm²
triangle_area&lt;-function(vertices,faces) {
  a&lt;-vertices[faces[,2],]-vertices[faces[,1],]
  b&lt;-vertices[faces[,3],]-vertices[faces[,1],]
  result&lt;-sqrt((a[,2]*b[,3]-a[,3]*b[,2])^2+(a[,3]*b[,1]-a[,1]*b[,3])^2+
               (a[,1]*b[,2]-a[,2]*b[,1])^2)/2
  return(result)
}
# the Desikan-Killiany atlas: the points of each region (numbered from 0), and the lobe of each
atlas&lt;-ggseg.formats::dk()
atlas_points&lt;-atlas$data$vertices
atlas_lobes&lt;-unique(as.data.frame(atlas$core)[,c("label","lobe")])
hemispheres&lt;-c(lh="left",rh="right")
faces&lt;-list()
points&lt;-data.frame()
pial_area&lt;-0
for(h in names(hemispheres)) {
  pial&lt;-read_surface(h,"pial")
  white&lt;-read_surface(h,"white")$vertices
  middle&lt;-read_surface(h,"midthickness")$vertices
  # the inflated surface comes from ggseg.formats, already in this frame but with each hemisphere
  # around x = 0: they move apart, their inner sides 4 mm from the middle
  inflated&lt;-as.matrix(ggseg.formats::get_brain_mesh(h,"inflated")$vertices)
  inflated[,1]&lt;-if(h=="lh") inflated[,1]-max(inflated[,1])-4 else inflated[,1]-min(inflated[,1])+4
  faces[[h]]&lt;-pial$faces
  # the region of each point; the points of no region are the medial wall, where the hemisphere is
  # cut away from the structures under it (the atlas calls a part of it "corpus callosum")
  region&lt;-rep("medialwall",nrow(pial$vertices))
  for(k in grep(paste0("^",h,"_"),atlas_points$label))
    region[atlas_points$vertices[[k]]+1]&lt;-sub("^[lr]h_","",atlas_points$label[k])
  # the area of the cortex around each point, measured halfway through its thickness: a third of
  # each triangle that the point is a corner of
  triangles&lt;-triangle_area(middle,pial$faces)
  area&lt;-as.vector(rowsum(rep(triangles/3,3),as.vector(pial$faces)))
  pial_area&lt;-pial_area+sum(triangle_area(pial$vertices,pial$faces))
  # the thickness at a point: the distance from the outer (pial) surface of the cortex to the inner
  # (white) one, which have the same points
  points&lt;-rbind(points,data.frame(hemisphere=hemispheres[[h]],region=region,pial$vertices,
                                  inflated_x=inflated[,1],inflated_y=inflated[,2],
                                  inflated_z=inflated[,3],middle_x=middle[,1],
                                  middle_y=middle[,2],middle_z=middle[,3],area=area,
                                  thickness=sqrt(rowSums((pial$vertices-white)^2))))
}
points$lobe&lt;-atlas_lobes$lobe[match(paste0(substr(points$hemisphere,1,1),"h_",points$region),
                                    atlas_lobes$label)]
xyz&lt;-as.matrix(points[,c("x","y","z")])</code></pre></div></div>
</details>
</div>
</section>
<section id="the-wrap" class="level3">
<h3 class="anchored" data-anchor-id="the-wrap">The wrap</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4"><pre><code class="language-r"># the wrap of each hemisphere: the convex hull of its points. Each row of hull$normals is the plane
# of one of the hull's triangles, a x + b y + c z + d = 0, with (a, b, c) pointing outwards. The
# depth of a point under the wrap is its distance to the nearest of those planes, worked out for
# 2,000 points at a time to keep the table of distances small
points$depth&lt;-NA
wrap_area&lt;-0
for(h in hemispheres) {
  rows&lt;-which(points$hemisphere==h)
  hull&lt;-geometry::convhulln(xyz[rows,],output.options="n FA")
  wrap_area&lt;-wrap_area+hull$area
  for(block in split(rows,ceiling(seq_along(rows)/2000))) {
    distance&lt;-xyz[block,]%*%t(hull$normals[,1:3])+
      matrix(hull$normals[,4],length(block),nrow(hull$normals),byrow=TRUE)
    points$depth[block]&lt;-apply(-distance,1,min)
  }
}</code></pre></div></div>
</details>
</div>
</section>
<section id="the-regions-and-the-lobes" class="level3">
<h3 class="anchored" data-anchor-id="the-regions-and-the-lobes">The regions and the lobes</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5"><pre><code class="language-r"># the names of the regions and of the lobes and what they do, simplified from textbooks (see the
# sources); "medialwall" is not a region of the cortex
regions&lt;-read.csv(sep="|",text="code|name|role
bankssts|Superior temporal sulcus|Its banks: making sense of speech, faces and movements
caudalanteriorcingulate|Caudal anterior cingulate|Noticing mistakes and conflicts, and pain
caudalmiddlefrontal|Caudal middle frontal gyrus|Moving the eyes (frontal eye field), attention
cuneus|Cuneus|Seeing: visual areas for the lower half of the view
entorhinal|Entorhinal cortex|The gateway to the hippocampus: memory and finding the way
fusiform|Fusiform gyrus|Recognising faces, bodies and written words
inferiorparietal|Inferior parietal lobule|Reading, numbers and meaning (the angular gyrus)
inferiortemporal|Inferior temporal gyrus|Recognising objects by sight
isthmuscingulate|Isthmus of the cingulate|Memory and finding the way (the retrosplenial cortex)
lateraloccipital|Lateral occipital cortex|Seeing shapes, objects and motion
lateralorbitofrontal|Lateral orbitofrontal cortex|Learning from rewards and losses
lingual|Lingual gyrus|Seeing: visual areas for the upper half of the view
medialorbitofrontal|Medial orbitofrontal cortex|The value of things, and choosing between them
middletemporal|Middle temporal gyrus|The meanings of words and things
parahippocampal|Parahippocampal gyrus|Recognising places and scenes, and memory
paracentral|Paracentral lobule|Moving and feeling the legs and feet
parsopercularis|Pars opercularis|Speaking: part of Broca's area, mostly on the left
parsorbitalis|Pars orbitalis|The meanings of words and sentences
parstriangularis|Pars triangularis|Language: part of Broca's area, mostly on the left
pericalcarine|Pericalcarine cortex|Seeing: the primary visual cortex, first to get the eyes' signals
postcentral|Postcentral gyrus|Touch and the sense of the body: the primary somatosensory cortex
posteriorcingulate|Posterior cingulate|Remembering, thinking about oneself and daydreaming
precentral|Precentral gyrus|Moving the body: the primary motor cortex
precuneus|Precuneus|Imagining scenes, remembering, and the self in space
rostralanteriorcingulate|Rostral anterior cingulate|Emotions, and keeping them in check
rostralmiddlefrontal|Rostral middle frontal gyrus|Planning, holding things in mind, self-control
superiorfrontal|Superior frontal gyrus|Planning movements (supplementary motor area), thinking
superiorparietal|Superior parietal lobule|Where things are, and reaching for them
superiortemporal|Superior temporal gyrus|Hearing and understanding speech (Wernicke's area)
supramarginal|Supramarginal gyrus|The sounds of words, and using tools and gestures
frontalpole|Frontal pole|The most abstract planning: keeping other options in mind
temporalpole|Temporal pole|Knowing people and things, and emotion
transversetemporal|Transverse temporal gyrus|Hearing: the primary auditory cortex (Heschl's gyrus)
insula|Insula|Feeling the inside of the body, taste, and disgust
medialwall|Medial wall|Not cortex: where the hemisphere is cut away from the structures under it")
lobes&lt;-read.csv(sep="|",text="code|name|role
frontal|Frontal lobe|Planning, deciding, speaking and moving
parietal|Parietal lobe|Touch, and where things are
temporal|Temporal lobe|Hearing, language, memory and recognising things
occipital|Occipital lobe|Seeing
cingulate|Cingulate gyrus|Emotion, attention and memory
insula|Insula|Feelings from inside the body, and taste")
# a region's (or a lobe's) area in cm², and its thickness and its depth under the wrap in mm,
# weighted by the area around each point; deep: the share of its area more than 5 mm under the wrap
summarise_cortex&lt;-function(x,group) {
  totals&lt;-rowsum(cbind(area=x$area,thickness=x$thickness*x$area,depth=x$depth*x$area,
                       deep=(x$depth&gt;5)*x$area),group)
  result&lt;-data.frame(key=rownames(totals),area=totals[,"area"]/100,
                     thickness=totals[,"thickness"]/totals[,"area"],
                     depth=totals[,"depth"]/totals[,"area"],
                     deep=100*totals[,"deep"]/totals[,"area"])
  return(result)
}
cortex&lt;-points[!points$region%in%c("medialwall","corpuscallosum"),]
region_both&lt;-summarise_cortex(cortex,cortex$region)
region_both$lobe&lt;-cortex$lobe[match(region_both$key,cortex$region)]
region_both$name&lt;-regions$name[match(region_both$key,regions$code)]
region_side&lt;-summarise_cortex(cortex,paste(cortex$hemisphere,cortex$region))
lobe_both&lt;-summarise_cortex(cortex,cortex$lobe)
lobe_both$name&lt;-lobes$name[match(lobe_both$key,lobes$code)]
lobe_both$share&lt;-100*lobe_both$area/sum(lobe_both$area)</code></pre></div></div>
</details>
</div>
</section>
<section id="the-structures-under-the-cortex-and-the-ventricles" class="level3">
<h3 class="anchored" data-anchor-id="the-structures-under-the-cortex-and-the-ventricles">The structures under the cortex and the ventricles</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6"><pre><code class="language-r"># FreeSurfer's segmentation of fsaverage (aseg.mgz): a volume of 256 × 256 × 256 cubes of 1 mm, each
# labeled with the structure it lies in. The server of the fsbrain package keeps a copy (365 KB);
# the page keeps its download, and the checksum makes sure that it is the file the page was written
# for
download_file&lt;-function(url,file,tries=3) {
  for(k in seq_len(tries)) {
    done&lt;-tryCatch(download.file(url,file,mode="wb",quiet=TRUE)==0,error=function(e) FALSE)
    if(done)
      return(invisible(file))
    Sys.sleep(10)
  }
  stop("Could not download ",url)
}
cache&lt;-tools::R_user_dir("illustration","cache")
dir.create(cache,recursive=TRUE,showWarnings=FALSE)
aseg_file&lt;-file.path(cache,"fsaverage_aseg.mgz")
aseg_url&lt;-"https://rcmd.org/projects/nitestdata/subjects_dir/fsaverage/mri/aseg.mgz"
if(!file.exists(aseg_file))
  download_file(aseg_url,aseg_file)
stopifnot(unname(tools::md5sum(aseg_file))=="b4a8f385370e5c831cdbe2f2a00d2d51")
aseg&lt;-freesurferformats::read.fs.mgh(aseg_file,with_header=TRUE)
labels&lt;-aseg$data[,,,1]
# the cubes of each label (0 to 255), counted: 1,000 cubes of 1 mm make a cm³
cubes&lt;-tabulate(as.vector(labels)+1,nbins=256)
# from a cube (its column, row and slice, numbered from 1) to mm in the frame of the cortex, and
# the label of the cube at a point
voxel_matrix&lt;-freesurferformats::mghheader.vox2ras.tkreg(aseg$header)
voxel_xyz&lt;-function(ijk) {
  result&lt;-(cbind(ijk-1,1)%*%t(voxel_matrix))[,1:3,drop=FALSE]
  return(result)
}
label_at&lt;-function(xyz) {
  ijk&lt;-round((cbind(xyz,1)%*%t(solve(voxel_matrix)))[,1:3,drop=FALSE])+1
  inside&lt;-rowSums(ijk&gt;=1&amp;ijk&lt;=256)==3
  result&lt;-rep(NA,nrow(xyz))
  result[inside]&lt;-labels[ijk[inside,,drop=FALSE]]
  return(result)
}
# the volume and the surfaces should lie in the same frame: the points halfway through the cortex
# should fall in cubes labeled cortex (3 on the left, 42 on the right). The share of them that do,
# with the volume where it is and moved by up to 2 mm in each direction
on_cortex&lt;-function(shift,middle,expected) {
  result&lt;-100*mean(label_at(sweep(middle,2,shift,"+"))==expected,na.rm=TRUE)
  return(result)
}
middle&lt;-as.matrix(points[,c("middle_x","middle_y","middle_z")])
moves&lt;-expand.grid(dx=-2:2,dy=-2:2,dz=-2:2)
moves$share&lt;-apply(moves,1,on_cortex,middle=middle,
                   expected=ifelse(points$hemisphere=="left",3,42))
in_place&lt;-moves$share[moves$dx==0&amp;moves$dy==0&amp;moves$dz==0]</code></pre></div></div>
</details>
</div>
<p>The volume lies in the frame of the cortex: 74% of the points halfway through the cortex fall in cubes labeled cortex (most of the others lie on the medial wall or at the edge of the cortex), and no move of up to 2 mm in any direction does better.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7"><pre><code class="language-r"># the structures under the cortex and the ventricles: their names, the labels of their cubes on the
# left, on the right or in the middle, and what they do
deep_list&lt;-read.csv(sep="|",colClasses="character",text="code|name|left|right|middle|role
cerebellum|Cerebellum|7 8|46 47||Balance, coordination and the timing of movements
brainstem|Brain stem|||16|Breathing, heartbeat, sleep and waking; joins the brain to the spinal cord
thalamus|Thalamus|10|49||The relay station of the senses (all but smell) on the way to the cortex
caudate|Caudate nucleus|11|50||Basal ganglia: learning, goals and habits
putamen|Putamen|12|51||Basal ganglia: movement and habits
pallidum|Globus pallidus|13|52||Basal ganglia: lets movements go ahead or holds them back
hippocampus|Hippocampus|17|53||Making new memories, and finding the way
amygdala|Amygdala|18|54||Emotion, fear, and noticing danger
accumbens|Nucleus accumbens|26|58||Reward and motivation
ventraldc|Ventral diencephalon|28|60||The hypothalamus and nuclei around it: hunger, sleep, hormones
callosum|Corpus callosum|||251 252 253 254 255|The bridge of nerve fibres between the hemispheres
chiasm|Optic chiasm|||85|Where the optic nerves cross: each hemisphere sees the opposite half")
ventricle_list&lt;-read.csv(sep="|",colClasses="character",text="code|name|left|right|middle|role
lateral|Lateral ventricles|4 5|43 44||One in each hemisphere, arching back into the temporal lobe
third|Third ventricle|||14|A narrow slit between the two halves of the thalamus
fourth|Fourth ventricle|||15|Between the brain stem and the cerebellum; the fluid flows out from it
choroid|Choroid plexus|31|63||Small blood vessels in the ventricles that make most of the fluid")
# the volume of a list of labels, in cm³, and of each structure on each side
label_volume&lt;-function(numbers) {
  result&lt;-if(numbers=="") 0 else sum(cubes[as.integer(strsplit(numbers," ")[[1]])+1])/1000
  return(result)
}
for(side in c("left","right","middle")) {
  deep_list[[paste0(side,"_volume")]]&lt;-sapply(deep_list[[side]],label_volume,USE.NAMES=FALSE)
  ventricle_list[[paste0(side,"_volume")]]&lt;-sapply(ventricle_list[[side]],label_volume,
                                                   USE.NAMES=FALSE)
}
deep_list$volume&lt;-deep_list$left_volume+deep_list$right_volume+deep_list$middle_volume
ventricle_list$volume&lt;-ventricle_list$left_volume+ventricle_list$right_volume+
  ventricle_list$middle_volume
# the brain: every labeled cube but those of the spaces filled with fluid (the ventricles and the
# fluid around the brain stem)
fluid&lt;-c(4,5,14,15,24,43,44,72)
brain_volume&lt;-(sum(cubes[-1])-sum(cubes[fluid+1]))/1000</code></pre></div></div>
</details>
</div>
</section>
<section id="the-tracts" class="level3">
<h3 class="anchored" data-anchor-id="the-tracts">The tracts</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8"><pre><code class="language-r">tracts&lt;-ggseg.formats::tracula()$data$centerlines
# the tracts come in a frame of their own, and mirrored: those of the left hemisphere ("lh.") lie
# at positive x. Mirrored back, they are laid on the volume where most of their points fall in
# white matter (2, 41, 7, 46, 77) or in the deep structures that they cross (the brain stem 16, the
# ventral diencephalon 28 and 60, the corpus callosum 251 to 255, the thalamus 10 and 49, the optic
# chiasm 85): first every 1 mm up to 30 mm forwards or backwards and up or down, then every 0.5 mm
# around the best, from side to side too
tract_points&lt;-lapply(tracts$points,function(m) cbind(-m[,1],m[,2],m[,3]))
all_points&lt;-do.call(rbind,tract_points)
white&lt;-c(2,41,7,46,77,16,28,60,251:255,10,49,85)
in_white&lt;-function(shift,xyz) {
  result&lt;-100*mean(label_at(sweep(xyz,2,shift,"+"))%in%white)
  return(result)
}
first_moves&lt;-expand.grid(dx=0,dy=-30:30,dz=-30:30)
first_moves$share&lt;-apply(first_moves,1,in_white,xyz=all_points)
start&lt;-first_moves[which.max(first_moves$share),]
moves_near&lt;-expand.grid(dx=seq(-2,2,by=0.5),dy=start$dy+seq(-1.5,1.5,by=0.5),
                        dz=start$dz+seq(-1.5,1.5,by=0.5))
moves_near$share&lt;-apply(moves_near,1,in_white,xyz=all_points)
tract_fit&lt;-moves_near[which.max(moves_near$share),]
unmoved&lt;-in_white(c(0,0,0),all_points)
tract_shift&lt;-c(tract_fit$dx,tract_fit$dy,tract_fit$dz)
tract_points&lt;-lapply(tract_points,function(m) sweep(m,2,tract_shift,"+"))
# each tract: its side, its code without the side ("af", "cc.genu") and its length in mm
code&lt;-sub("\\.bbr\\.prep$","",tracts$label)
tract_list&lt;-data.frame(side=ifelse(grepl("^lh\\.",code),"left",
                                   ifelse(grepl("^rh\\.",code),"right","middle")),
                       code=sub("^[lr]h\\.","",code))
tract_list$length&lt;-sapply(tract_points,function(m) sum(sqrt(rowSums(diff(m)^2))))</code></pre></div></div>
</details>
</div>
<p>Mirrored and moved 14.5 mm backwards, 10.0 mm upwards and 0.5 mm to the right, 89% of the points of the tracts fall in white matter or in the deep structures that they cross, the most for any move tried; where they come, 50% do.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9"><pre><code class="language-r"># the tracts: their names, their group and what they do
tract_names&lt;-read.csv(sep="|",text="code|name|group|role
cc.rostrum|Corpus callosum: rostrum|commissural|Links the orbitofrontal cortex of the two sides
cc.genu|Corpus callosum: genu|commissural|Links the prefrontal cortex of the two hemispheres
cc.bodypf|Corpus callosum: body, prefrontal|commissural|Links the prefrontal cortex of the two sides
cc.bodypm|Corpus callosum: body, premotor|commissural|Links the premotor cortex of the two sides
cc.bodyc|Corpus callosum: body, central|commissural|Links the motor and touch strips of both sides
cc.bodyp|Corpus callosum: body, parietal|commissural|Links the parietal lobes
cc.bodyt|Corpus callosum: body, temporal|commissural|Links the temporal lobes
cc.splenium|Corpus callosum: splenium|commissural|Links the occipital lobes
acomm|Anterior commissure|commissural|Links the two temporal lobes, and smell
af|Arcuate fasciculus|association|Language: links the speech areas at the front and at the back
slf1|Superior longitudinal fasciculus I|association|Movement and attention, along the top
slf2|Superior longitudinal fasciculus II|association|Attention to where things are
slf3|Superior longitudinal fasciculus III|association|Language and gestures, along the side
ilf|Inferior longitudinal fasciculus|association|Recognising what is seen: occipital to temporal
mlf|Middle longitudinal fasciculus|association|Hearing and language: temporal to parietal
emc|Extreme capsule|association|Language: links the temporal lobe with the frontal lobe
fat|Frontal aslant tract|association|Starting to speak and act: links the top of the frontal lobe
uf|Uncinate fasciculus|limbic|Emotion and memory: temporal pole to orbitofrontal cortex
cbd|Cingulum, upper part|limbic|Attention and emotion: runs inside the cingulate gyrus
cbv|Cingulum, lower part|limbic|Memory: links the cingulate gyrus with the hippocampal region
fx|Fornix|limbic|Memory: carries signals out of the hippocampus
cst|Corticospinal tract|projection|Moving: from the motor cortex down to the spinal cord
atr|Anterior thalamic radiation|projection|Links the thalamus with the front of the brain
or|Optic radiation|projection|Seeing: from the thalamus to the visual cortex
ar|Acoustic radiation|projection|Hearing: from the thalamus to the auditory cortex
mcp|Middle cerebellar peduncle|cerebellar|Carries signals from the cortex, through the pons")
groups&lt;-c(commissural="Commissural: across the hemispheres",
          association="Association: within a hemisphere",
          projection="Projection: cortex to thalamus and spinal cord",
          limbic="Limbic: memory and emotion",cerebellar="Cerebellar: to the cerebellum")
tract_list&lt;-cbind(tract_list,tract_names[match(tract_list$code,tract_names$code),-1])</code></pre></div></div>
</details>
</div>
</section>
<section id="what-is-drawn" class="level3">
<h3 class="anchored" data-anchor-id="what-is-drawn">What is drawn</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10"><pre><code class="language-r"># a simpler copy of a surface: its points are gathered into cubes of `size` mm and the points of a
# cube become one, their mean; triangles that shrink to a line or a point go
simplify_mesh&lt;-function(vertices,faces,size) {
  cube&lt;-paste(round(vertices[,1]/size),round(vertices[,2]/size),round(vertices[,3]/size))
  group&lt;-match(cube,unique(cube))
  centres&lt;-rowsum(vertices,group)/as.vector(table(group))
  triangles&lt;-matrix(group[faces],ncol=3)
  triangles&lt;-triangles[triangles[,1]!=triangles[,2]&amp;triangles[,2]!=triangles[,3]&amp;
                         triangles[,1]!=triangles[,3],,drop=FALSE]
  triangles&lt;-triangles[!duplicated(t(apply(triangles,1,sort))),,drop=FALSE]
  result&lt;-list(vertices=centres,faces=triangles-1)
  return(result)
}
# the surface of a structure from the cubes of its labels. The cubes are blurred a little (by a bell
# curve of 0.8 mm, one direction at a time), so that the surface is smooth rather than made of
# steps; misc3d's marching cubes trace it where the blurred value is one half; and it is simplified
# into cubes of 2 mm, or 3 mm for the largest structures (over 20 cm³)
smooth_line&lt;-function(v,k) {
  n&lt;-length(v)
  h&lt;-(length(k)-1)/2
  result&lt;-as.vector(stats::filter(c(rep(0,h),v,rep(0,h)),k,sides=2))[(h+1):(h+n)]
  return(result)
}
blur&lt;-function(a,sigma) {
  k&lt;-dnorm(-3:3,sd=sigma)
  k&lt;-k/sum(k)
  a&lt;-apply(a,c(2,3),smooth_line,k=k)
  a&lt;-aperm(apply(a,c(1,3),smooth_line,k=k),c(2,1,3))
  result&lt;-aperm(apply(a,c(1,2),smooth_line,k=k),c(2,3,1))
  return(result)
}
structure_labels&lt;-function(x) {
  result&lt;-as.integer(unlist(strsplit(c(x$left,x$right,x$middle)," ")))
  return(result)
}
label_surface&lt;-function(numbers) {
  inside&lt;-array(labels%in%numbers,dim(labels))
  found&lt;-which(inside,arr.ind=TRUE)
  low&lt;-pmax(apply(found,2,min)-4,1)
  high&lt;-pmin(apply(found,2,max)+4,256)
  box&lt;-inside[low[1]:high[1],low[2]:high[2],low[3]:high[3]]+0
  soup&lt;-misc3d::computeContour3d(blur(box,0.8),maxvol=1,level=0.5,x=low[1]:high[1],
                                 y=low[2]:high[2],z=low[3]:high[3])
  # the corners of the triangles, each written once
  key&lt;-paste(round(soup[,1],4),round(soup[,2],4),round(soup[,3],4))
  corners&lt;-voxel_xyz(soup[!duplicated(key),,drop=FALSE])
  triangles&lt;-matrix(match(key,unique(key)),ncol=3,byrow=TRUE)
  result&lt;-simplify_mesh(corners,triangles,if(nrow(found)&gt;20000) 3 else 2)
  return(result)
}
deep_shapes&lt;-list()
for(k in seq_len(nrow(deep_list)))
  deep_shapes[[deep_list$code[k]]]&lt;-label_surface(structure_labels(deep_list[k,]))
ventricle_shapes&lt;-list()
for(k in seq_len(nrow(ventricle_list)))
  ventricle_shapes[[ventricle_list$code[k]]]&lt;-label_surface(structure_labels(ventricle_list[k,]))
# a coarse copy of the cortex, drawn as glass around the structures and the tracts. fsaverage5 was
# made by dividing each triangle of an icosahedron into four, five times over, and its first 2,562
# points are those of the fourth time: their triangles are the convex hull of those points on the
# sphere, each turned to face outwards as the lighting needs
coarse&lt;-list()
for(h in names(hemispheres)) {
  sphere&lt;-read_surface(h,"sphere")$vertices[1:2562,]
  sphere&lt;-sweep(sphere,2,colMeans(sphere))
  triangles&lt;-geometry::convhulln(sphere)
  a&lt;-sphere[triangles[,2],]-sphere[triangles[,1],]
  b&lt;-sphere[triangles[,3],]-sphere[triangles[,1],]
  normal&lt;-cbind(a[,2]*b[,3]-a[,3]*b[,2],a[,3]*b[,1]-a[,1]*b[,3],a[,1]*b[,2]-a[,2]*b[,1])
  inwards&lt;-rowSums(normal*sphere[triangles[,1],])&lt;0
  triangles[inwards,]&lt;-triangles[inwards,c(1,3,2)]
  coarse[[h]]&lt;-list(vertices=xyz[points$hemisphere==hemispheres[[h]],][1:2562,],
                    faces=triangles-1)
}
# the cortex in pieces, one for each region of each hemisphere, so that the pointer can name the
# region: the rows of its points in `points`, and its triangles numbered from 0 within the piece. A
# triangle belongs to the region of its first corner
points$region[points$region=="corpuscallosum"]&lt;-"medialwall"
pieces&lt;-list()
for(h in names(hemispheres)) {
  rows&lt;-which(points$hemisphere==hemispheres[[h]])
  corner&lt;-points$region[rows][faces[[h]][,1]]
  for(r in unique(corner)) {
    triangles&lt;-faces[[h]][corner==r,,drop=FALSE]
    used&lt;-sort(unique(as.vector(triangles)))
    pieces[[length(pieces)+1]]&lt;-list(hemisphere=hemispheres[[h]],region=r,rows=rows[used],
                                    faces=matrix(match(triangles,used)-1,ncol=3))
  }
}</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11"><pre><code class="language-r">dark_gray&lt;-"#6b6b6b" # also the color of the notes and the labels
light_gray&lt;-"#d9d9d9" # the medial wall and the corpus callosum
glass_gray&lt;-"#a8a8a8"
# the lobes, the structures under the cortex, the groups of tracts and the ventricles, told apart
# also by color-blind readers (every pair checked)
lobe_colours&lt;-c(frontal="#56B4E9",parietal="#E69F00",temporal="#009E73",occipital="#CC79A7",
                cingulate="#D55E00",insula="#F0E442")
deep_colours&lt;-c(cerebellum="#E69F00",brainstem="#4a4a4a",thalamus="#0072B2",caudate="#56B4E9",
                putamen="#CC79A7",pallidum="#542788",hippocampus="#F0E442",amygdala="#D55E00",
                accumbens="#009E73",ventraldc="#8c564b",callosum=light_gray,chiasm="#1a1a1a")
group_colours&lt;-c(commissural="#0072B2",association="#E69F00",projection="#009E73",
                 limbic="#CC79A7",cerebellar="#D55E00")
ventricle_colours&lt;-c(lateral="#0072B2",third="#56B4E9",fourth="#009E73",choroid="#D55E00")
# the color scales of the depth under the wrap (pale on the surface, dark deep down) and of the
# thickness, and the four bands of depth of question 2
depth_scale&lt;-list(list(0,"#deebf7"),list(0.25,"#9ecae1"),list(0.5,"#4292c6"),list(0.75,"#2171b5"),
                  list(1,"#08306b"))
thickness_scale&lt;-list(list(0,"#fde725"),list(0.25,"#5ec962"),list(0.5,"#21918c"),
                      list(0.75,"#3b528b"),list(1,"#440154"))
band_colours&lt;-c("#c6dbef","#6baed6","#2171b5","#08306b")
# the source of a chart, as a note under it, and the common layout; note_shift moves the note down
# by a number of pixels, which stays the same however tall the plot is
chart&lt;-function(p,title,source,annotations=list(),margin=list(t=70,b=90),note_y=-0.16,
                note_shift=0,...) {
  note&lt;-list(text=paste("Source:",source),xref="paper",yref="paper",x=0,y=note_y,xanchor="left",
             yanchor="top",yshift=note_shift,align="left",showarrow=FALSE,
             font=list(size=11,color=dark_gray))
  result&lt;-layout(p,
                 title=list(text=title,x=0.02,xanchor="left",y=0.97,yanchor="top"),
                 margin=margin,
                 annotations=c(annotations,list(note)),
                 ...) %&gt;%
    config(displaylogo=FALSE)
  return(result)
}
legend_top&lt;-list(orientation="h",x=0,y=1.02,yanchor="bottom")
fsaverage&lt;-"FreeSurfer's fsaverage5 and the Desikan-Killiany atlas (ggseg.meshes, ggseg.formats)."
# 3D charts. A mesh of triangles, numbered from 0, in tenths of a mm as whole numbers: plotly for R
# writes any other number with 17 digits, -38.700000000000003 for -38.7. The axes are hidden, and
# the tracts are drawn in tenths of a mm too
add_mesh&lt;-function(p,vertices,faces,name,...) {
  result&lt;-add_trace(p,type="mesh3d",x=round(10*vertices[,1]),y=round(10*vertices[,2]),
                    z=round(10*vertices[,3]),i=faces[,1],j=faces[,2],k=faces[,3],name=name,...)
  return(result)
}
# the last step of a 3D chart: build it, drop its second copy of every number ("attrs"), and give
# each trace its color and its text for the pointer, which plotly for R would leave out (the
# color of a mesh, in whose place it puts a color scale) or repeat for every point (the text); NA
# leaves a trace as it is
finish_3d&lt;-function(p,colours,meta) {
  result&lt;-plotly_build(p)
  result$x$attrs&lt;-NULL
  for(k in seq_along(result$x$data)) {
    if(!is.na(colours[k])) {
      result$x$data[[k]]$color&lt;-colours[[k]]
      result$x$data[[k]]$colorscale&lt;-NULL
    }
    if(!is.na(meta[k])) {
      result$x$data[[k]]$meta&lt;-meta[[k]]
      result$x$data[[k]]$hovertemplate&lt;-"%{meta}&lt;extra&gt;&lt;/extra&gt;"
    }
  }
  return(result)
}
# the light, from above, and the scene: no axes, the brain in its true shape, turned by dragging
lighting&lt;-list(ambient=0.45,diffuse=0.75,specular=0.15,roughness=0.6,fresnel=0.1)
glass_lighting&lt;-list(ambient=0.9,diffuse=0.2,specular=0,roughness=1,fresnel=0.2)
above&lt;-list(x=0,y=0,z=1e5)
scene&lt;-function(eye=list(x=-1.35,y=0.25,z=0.3),domain=list(x=c(0,1),y=c(0,1))) {
  axis&lt;-list(visible=FALSE)
  result&lt;-list(xaxis=axis,yaxis=axis,zaxis=axis,aspectmode="data",dragmode="turntable",
               camera=list(eye=eye),domain=domain)
  return(result)
}
# buttons under a 3D chart that turn the brain to one of six views
views&lt;-list(Left=c(-1.5,0,0.1),Right=c(1.5,0,0.1),Front=c(0,1.5,0.1),Back=c(0,-1.5,0.1),
            Top=c(0,0,1.6),Below=c(0,0,-1.6))
view_buttons&lt;-list()
for(v in names(views)) {
  up&lt;-if(v%in%c("Top","Below")) list(x=0,y=1,z=0) else list(x=0,y=0,z=1)
  eye&lt;-list(x=views[[v]][1],y=views[[v]][2],z=views[[v]][3])
  camera&lt;-list(eye=eye,up=up,center=list(x=0,y=0,z=0))
  view_buttons[[v]]&lt;-list(label=v,method="relayout",args=list(list(scene.camera=camera)))
}
view_menu&lt;-list(type="buttons",direction="right",x=0,y=0,xanchor="left",yanchor="top",
                showactive=FALSE,buttons=unname(view_buttons))
# a volume in cm³, to a tenth, or to a hundredth below 0.1 cm³ (the optic chiasm)
volume_text&lt;-function(x) {
  result&lt;-if(x&lt;0.1) format(round(x,2),nsmall=2) else one(x)
  return(result)
}
# the volume of a structure: on each side, or in all for one in the middle
volume_words&lt;-function(x) {
  result&lt;-if(x$left_volume&gt;0) paste0(volume_text(x$left_volume)," cm³ on the left, ",
                                     volume_text(x$right_volume)," on the right") else
    paste0(volume_text(x$volume)," cm³")
  return(result)
}
# the text for the pointer: a name in bold, and lines under it
pointer_text&lt;-function(name,...) {
  result&lt;-paste0("&lt;b&gt;",name,"&lt;/b&gt;&lt;br&gt;",paste(...,sep="&lt;br&gt;"))
  return(result)
}</code></pre></div></div>
</details>
</div>
<hr>
</section>
</section>
<section id="what-are-the-parts-of-the-cortex" class="level2">
<h2 class="anchored" data-anchor-id="what-are-the-parts-of-the-cortex">1. What are the parts of the cortex?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12"><pre><code class="language-r">lobe_both&lt;-lobe_both[order(-lobe_both$area),]
total_area&lt;-sum(cortex$area)/100
side_area&lt;-tapply(cortex$area,cortex$hemisphere,sum)/100
largest&lt;-region_both[which.max(region_both$area),]
smallest&lt;-region_both[which.min(region_both$area),]
share&lt;-setNames(lobe_both$share,lobe_both$key)</code></pre></div></div>
</details>
</div>
<p><strong>Six lobes and 34 regions in each hemisphere.</strong> Spread out flat, the cortex of the average brain would cover <strong>1,286 cm²</strong>, a square of 36 cm on each side (measured halfway through its thickness); the left hemisphere has 0.1% less of it than the right. The <strong>frontal lobe</strong> has 36% of it, the <strong>parietal lobe</strong> 25%, the <strong>temporal lobe</strong> 21% and the <strong>occipital lobe</strong> 11%; the <strong>cingulate gyrus</strong>, on the inner side of each hemisphere, and the <strong>insula</strong>, hidden under the frontal and temporal lobes, share the rest. Of the regions, the superior frontal gyrus is the largest, 115 cm² in the two hemispheres together, and the frontal pole the smallest, 5 cm².</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13"><pre><code class="language-r">p&lt;-plot_ly()
lobe_trace&lt;-c()
region_trace&lt;-c()
meta&lt;-c()
for(piece in pieces) {
  region&lt;-regions[regions$code==piece$region,]
  lobe&lt;-region_both$lobe[region_both$key==piece$region]
  name&lt;-paste0(region$name,", ",piece$hemisphere)
  p&lt;-add_mesh(p,xyz[piece$rows,],piece$faces,name,flatshading=FALSE,lighting=lighting,
              lightposition=above,showlegend=FALSE)
  if(piece$region=="medialwall") {
    lobe_trace&lt;-c(lobe_trace,light_gray)
    region_trace&lt;-c(region_trace,light_gray)
    meta&lt;-c(meta,pointer_text(name,region$role))
  } else {
    side&lt;-region_side[region_side$key==paste(piece$hemisphere,piece$region),]
    lobe_trace&lt;-c(lobe_trace,lobe_colours[[lobe]])
    region_trace&lt;-c(region_trace,atlas$palette[[paste0(substr(piece$hemisphere,1,1),"h_",
                                                       piece$region)]])
    meta&lt;-c(meta,pointer_text(name,lobes$name[lobes$code==lobe],region$role,
                              paste0(number(side$area)," cm² of cortex, ",one(side$thickness),
                                     " mm thick on average")))
  }
}
colour_menu&lt;-list(type="buttons",direction="right",x=0,y=1,xanchor="left",yanchor="bottom",
                  buttons=list(list(label="Lobes",method="restyle",
                                    args=list(list(color=as.list(lobe_trace)))),
                               list(label="Regions",method="restyle",
                                    args=list(list(color=as.list(region_trace))))))
p %&gt;%
  chart("The cortex of the average brain, by lobe",
        paste(fsaverage,"Drag to turn, scroll to zoom."),
        margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,scene=scene(),
        updatemenus=list(colour_menu,view_menu)) %&gt;%
  finish_3d(lobe_trace,meta)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Interactive chart: The cortex of the average brain, by lobe</a></p>
</div>
</div>
<p>The colors of the lobes follow the atlas, which counts the cingulate gyrus as a lobe of its own. The button <strong>Regions</strong> colors the 34 regions instead, and the pointer over a region gives its name, its lobe, what it does and its size. Each region does more than its one line says, and most of what we do takes many regions at once.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14"><pre><code class="language-r">children&lt;-data.frame(id=region_both$key,parent=region_both$lobe,label=region_both$name,
                     area=round(region_both$area,1),colour=lobe_colours[region_both$lobe])
# the insula is both a lobe and a region
children$id[children$id=="insula"]&lt;-"insula region"
# a lobe's box holds exactly its regions' boxes
parents&lt;-data.frame(id=lobe_both$key,parent="",label=lobe_both$name,
                    area=as.vector(tapply(children$area,children$parent,sum)[lobe_both$key]),
                    colour=lobe_colours[lobe_both$key])
p&lt;-plot_ly(rbind(parents,children),type="treemap",ids=~id,parents=~parent,labels=~label,
           values=~area,branchvalues="total",
           marker=list(colors=~colour,line=list(color="white",width=1)),
           texttemplate="%{label}&lt;br&gt;%{value:.0f} cm²",
           hovertemplate=paste0("%{label}: %{value:.0f} cm², %{percentRoot:.1%} of the cortex",
                                "&lt;extra&gt;&lt;/extra&gt;"))
chart(p,"The area of each lobe and region, both hemispheres, cm²",
      paste("FreeSurfer's fsaverage5, measured halfway through the cortex,",
            "and the Desikan-Killiany atlas."),
      uniformtext=list(minsize=10,mode="hide"),margin=list(t=50,b=50,l=0,r=0),note_y=0)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Interactive chart: The area of each lobe and region, both hemispheres, cm²</a></p>
</div>
</div>
<p>Each box is as large as the area of its lobe or region; a click on a lobe opens its box.</p>
<hr>
</section>
<section id="how-much-of-the-cortex-is-hidden-in-the-folds" class="level2">
<h2 class="anchored" data-anchor-id="how-much-of-the-cortex-is-hidden-in-the-folds">2. How much of the cortex is hidden in the folds?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15"><pre><code class="language-r">deep_share&lt;-100*sum(cortex$area[cortex$depth&gt;5])/sum(cortex$area)
surface_share&lt;-100*sum(cortex$area[cortex$depth&lt;=2])/sum(cortex$area)
# the depth that half of the area of the cortex lies deeper than
by_depth&lt;-order(cortex$depth)
half_depth&lt;-cortex$depth[by_depth][which(cumsum(cortex$area[by_depth])&gt;=sum(cortex$area)/2)[1]]
folded&lt;-pial_area/wrap_area
deepest&lt;-region_both[which.max(region_both$depth),]
shallowest&lt;-region_both[which.min(region_both$depth),]
most_folded&lt;-lobe_both[which.max(lobe_both$deep),]
least_folded&lt;-lobe_both[which.min(lobe_both$deep),]</code></pre></div></div>
</details>
</div>
<p><strong>Most of it.</strong> The outer surface of the cortex has 1.7 times the area of the wraps around the two hemispheres: 1,530 cm² against 926. Only 23% of the cortex lies within 2 mm of the wrap; 58% lies more than 5 mm under it, and half of it more than 7 mm under it. Deepest of all is the insula, 25 mm under the wrap on average, and the least deep the frontal pole, 0.6 mm.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16"><pre><code class="language-r"># the depth in whole mm; the thickness in tenths of a mm, the labels of its color bar in mm
depth_max&lt;-5*ceiling(quantile(cortex$depth,0.95)/5)
thickness_range&lt;-round(2*quantile(cortex$thickness,c(0.02,0.98)))/2
thickness_ticks&lt;-seq(10*thickness_range[[1]],10*thickness_range[[2]],by=5)
p&lt;-plot_ly()
colours&lt;-c()
meta&lt;-c()
coloured&lt;-c()
depth_values&lt;-list()
thickness_values&lt;-list()
for(k in seq_along(pieces)) {
  piece&lt;-pieces[[k]]
  region&lt;-regions[regions$code==piece$region,]
  name&lt;-paste0(region$name,", ",piece$hemisphere)
  inflated&lt;-as.matrix(points[piece$rows,c("inflated_x","inflated_y","inflated_z")])
  if(piece$region=="medialwall") {
    p&lt;-add_mesh(p,inflated,piece$faces,name,flatshading=FALSE,lighting=lighting,
                lightposition=above,showlegend=FALSE)
    colours&lt;-c(colours,light_gray)
    meta&lt;-c(meta,pointer_text(name,region$role))
  } else {
    depth&lt;-round(points$depth[piece$rows])
    p&lt;-add_mesh(p,inflated,piece$faces,name,intensity=depth,colorscale=depth_scale,cmin=0,
                cmax=depth_max,showscale=length(coloured)==0,flatshading=FALSE,
                colorbar=list(title=list(text="mm under&lt;br&gt;the wrap"),len=0.5,thickness=12),
                lighting=lighting,lightposition=above,showlegend=FALSE)
    side&lt;-region_side[region_side$key==paste(piece$hemisphere,piece$region),]
    colours&lt;-c(colours,NA)
    meta&lt;-c(meta,pointer_text(name,paste0(number(side$depth)," mm under the wrap on average, ",
                                          percent(side$deep)," of it more than 5 mm"),
                              paste0(one(side$thickness)," mm thick on average")))
    coloured&lt;-c(coloured,k)
    depth_values[[length(depth_values)+1]]&lt;-depth
    thickness_values[[length(thickness_values)+1]]&lt;-round(10*points$thickness[piece$rows])
  }
}
depth_button&lt;-list(label="Depth",method="restyle",
                   args=list(list(intensity=depth_values,colorscale=list(depth_scale),cmin=0,
                                  cmax=depth_max,colorbar.title.text="mm under&lt;br&gt;the wrap",
                                  colorbar.tickmode="auto"),
                             coloured-1))
thickness_button&lt;-list(label="Thickness",method="restyle",
                       args=list(list(intensity=thickness_values,colorscale=list(thickness_scale),
                                      cmin=min(thickness_ticks),cmax=max(thickness_ticks),
                                      colorbar.title.text="mm thick",colorbar.tickmode="array",
                                      colorbar.tickvals=list(thickness_ticks),
                                      colorbar.ticktext=list(one(thickness_ticks/10))),
                                 coloured-1))
measure_menu&lt;-list(type="buttons",direction="right",x=0,y=1,xanchor="left",yanchor="bottom",
                   buttons=list(depth_button,thickness_button))
p %&gt;%
  chart("The cortex blown up: how deep each point lies in the folded brain",
        paste(fsaverage,"Grey: the medial wall."),
        margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,scene=scene(),
        updatemenus=list(measure_menu,view_menu)) %&gt;%
  finish_3d(colours,meta)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Interactive chart: The cortex blown up: how deep each point lies in the folded brain</a></p>
</div>
</div>
<p>This is the same cortex as in the first chart, blown up like a balloon until its folds open out, as FreeSurfer does to show all of it at once; each point keeps the color of its depth in the folded brain. The dark patches are the floors of the grooves, and the large dark field on the side is the insula, which the frontal and temporal lobes fold over. The button <strong>Thickness</strong> colors the cortex by its thickness instead, the subject of question 3.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17"><pre><code class="language-r">bands&lt;-cut(cortex$depth,c(0,2,10,20,Inf),c("Within 2 mm","2 to 10 mm","10 to 20 mm","Over 20 mm"),
           right=FALSE)
band_area&lt;-rbind(tapply(cortex$area,list(cortex$lobe,bands),sum),all=tapply(cortex$area,bands,sum))
band_area[is.na(band_area)]&lt;-0
band_share&lt;-100*prop.table(band_area,1)
band_share&lt;-band_share[order(band_share[,"Over 20 mm"]+band_share[,"10 to 20 mm"]),]
lobe_label&lt;-ifelse(rownames(band_share)=="all","&lt;b&gt;Whole cortex&lt;/b&gt;",
                   lobes$name[match(rownames(band_share),lobes$code)])
p&lt;-plot_ly()
for(b in colnames(band_share))
  p&lt;-add_bars(p,y=lobe_label,x=round(band_share[,b],1),name=b,orientation="h",
              marker=list(color=band_colours[match(b,colnames(band_share))]),
              hovertemplate=paste0("%{y}: %{x:.0f}% ",lower_first(b),"&lt;extra&gt;&lt;/extra&gt;"))
chart(p,"How deep each lobe lies under the wrap, % of its area",
      paste("FreeSurfer's fsaverage5 and the Desikan-Killiany atlas.",
            "The wrap: the convex hull of each hemisphere."),
      barmode="stack",legend=c(legend_top,list(traceorder="normal")),margin=list(t=90,b=90),
      note_y=-0.2,xaxis=list(title="",ticksuffix="%",range=c(0,100)),
      yaxis=list(title="",categoryorder="array",categoryarray=lobe_label,automargin=TRUE))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Interactive chart: How deep each lobe lies under the wrap, % of its area</a></p>
</div>
</div>
<p>The lobes are not folded away alike: 100% of the insula lies more than 5 mm under the wrap, and 36% of the cingulate gyrus. The wrap reaches into no groove, so even the ridges of the cortex lie under it where a hemisphere curves inwards, as on its underside, between the temporal lobe and the frontal lobe.</p>
<hr>
</section>
<section id="where-is-the-cortex-thickest" class="level2">
<h2 class="anchored" data-anchor-id="where-is-the-cortex-thickest">3. Where is the cortex thickest?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18"><pre><code class="language-r">mean_thickness&lt;-weighted.mean(cortex$thickness,cortex$area)
by_thickness&lt;-region_both[order(region_both$thickness),]
thinnest&lt;-by_thickness[1,]
thickest&lt;-by_thickness[nrow(by_thickness),]
thin_four&lt;-by_thickness$key[1:4]
thick_four&lt;-rev(by_thickness$key)[1:4]
# the regions of seeing and touch at the back of the brain, and those of memory and emotion at its
# front and bottom
senses&lt;-c("pericalcarine","cuneus","lingual","lateraloccipital","postcentral","superiorparietal")
feelings&lt;-c("temporalpole","entorhinal","parahippocampal","insula","rostralanteriorcingulate",
            "caudalanteriorcingulate","medialorbitofrontal","frontalpole")
motor&lt;-region_both[region_both$key=="precentral",]
touch&lt;-region_both[region_both$key=="postcentral",]
left&lt;-region_side[grepl("^left",region_side$key),]
right&lt;-region_side[grepl("^right",region_side$key),]
region_both$left&lt;-left$thickness[match(paste("left",region_both$key),left$key)]
region_both$right&lt;-right$thickness[match(paste("right",region_both$key),right$key)]
side_gap&lt;-max(abs(region_both$left-region_both$right))</code></pre></div></div>
</details>
</div>
<p><strong>Between 1.8 and 4.5 mm, 2.7 on average.</strong> The four thinnest regions are the pericalcarine cortex, the cuneus, the postcentral gyrus and the superior parietal lobule, where sight and touch arrive, at the back of the brain. The four thickest are the temporal pole, the entorhinal cortex, the rostral anterior cingulate and the insula, at the front and at the bottom of the brain, where memory and emotion are handled. The two strips on either side of the central sulcus differ too: the precentral gyrus, which moves the body, is 2.6 mm thick, and the postcentral gyrus behind it, which feels it, 2.1 mm. The two hemispheres hardly differ: a region is at most 0.2 mm thicker on one side than on the other.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19"><pre><code class="language-r">p&lt;-plot_ly()
for(l in lobes$code) {
  x&lt;-region_both[region_both$lobe==l,]
  p&lt;-add_bars(p,data=x,y=~name,x=~round(thickness,2),name=lobes$name[lobes$code==l],
              orientation="h",marker=list(color=lobe_colours[[l]]),
              customdata=~paste0("left ",one(left),", right ",one(right)))
}
p&lt;-style(p,hovertemplate="%{y}: %{x:.1f} mm (%{customdata})&lt;extra&gt;&lt;/extra&gt;")
chart(p,"The mean thickness of each region of the cortex, mm",
      "fsaverage5 and the Desikan-Killiany atlas: the distance from the pial to the white surface.",
      legend=legend_top,margin=list(t=100,b=70,l=10),note_y=-0.07,
      xaxis=list(title="",ticksuffix=" mm"),
      yaxis=list(title="",categoryorder="array",categoryarray=by_thickness$name,automargin=TRUE))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Interactive chart: The mean thickness of each region of the cortex, mm</a></p>
</div>
</div>
<p>The thickness here is the distance from each point of the outer surface of the cortex to the same point of its inner surface, close to the way FreeSurfer measures it (<a href="https://doi.org/10.1073/pnas.200033797">Fischl and Dale 2000</a>). The button <strong>Thickness</strong> of the chart of question 2 shows it over the whole cortex.</p>
<hr>
</section>
<section id="what-lies-under-the-cortex" class="level2">
<h2 class="anchored" data-anchor-id="what-lies-under-the-cortex">4. What lies under the cortex?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20"><pre><code class="language-r">cerebellum&lt;-deep_list[deep_list$code=="cerebellum",]
cerebellum_share&lt;-100*cerebellum$volume/brain_volume
largest&lt;-deep_list[which.max(deep_list$volume),]
middle_kinds&lt;-c("thalamus","caudate","putamen","pallidum","hippocampus","amygdala","accumbens")
middle_structures&lt;-deep_list[deep_list$code%in%middle_kinds,]
largest_middle&lt;-middle_structures[which.max(middle_structures$volume),]
hippocampus&lt;-deep_list[deep_list$code=="hippocampus",]
amygdala&lt;-deep_list[deep_list$code=="amygdala",]</code></pre></div></div>
</details>
</div>
<p><strong>Twelve structures, and the largest by far is the cerebellum.</strong> The cerebellum takes up 155 cm³, 11% of the brain, which fills 1,409 cm³ without its spaces filled with fluid. Small as it is, it holds most of the brain’s nerve cells: about 69 of 86 billion, while the cerebral cortex and its white matter, 82% of the brain’s weight, hold only 19% of them (<a href="https://doi.org/10.1002/cne.21974">Azevedo et al.&nbsp;2009</a>). Of the structures in the middle of the brain, the thalamus is the largest, 8.6 cm³ on the left and 8.6 on the right; the <strong>hippocampus</strong>, where new memories are made, takes up 5.3 cm³ on each side, and the <strong>amygdala</strong>, of fear and emotion, 2.1.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21"><pre><code class="language-r">p&lt;-plot_ly()
for(h in names(hemispheres))
  p&lt;-add_mesh(p,coarse[[h]]$vertices,coarse[[h]]$faces,"Cortex",opacity=0.1,hoverinfo="skip",
              lighting=glass_lighting,showlegend=FALSE)
colours&lt;-c(glass_gray,glass_gray)
meta&lt;-c(NA,NA)
for(k in seq_len(nrow(deep_list))) {
  structure&lt;-deep_list[k,]
  shape&lt;-deep_shapes[[structure$code]]
  p&lt;-add_mesh(p,shape$vertices,shape$faces,structure$name,flatshading=FALSE,lighting=lighting,
              lightposition=above,showlegend=TRUE)
  colours&lt;-c(colours,deep_colours[[structure$code]])
  meta&lt;-c(meta,pointer_text(structure$name,structure$role,volume_words(structure)))
}
p %&gt;%
  chart("The structures under the cortex",
        paste("FreeSurfer's segmentation of fsaverage (aseg.mgz), from fsbrain's test data.",
              "A click on a name hides it."),
        margin=list(t=60,b=80,l=0,r=0),note_y=0,note_shift=-40,
        scene=scene(list(x=-1.25,y=0.75,z=0.3),list(x=c(0,0.8),y=c(0,1))),
        legend=list(x=1,xanchor="right",y=0.95,itemsizing="constant"),
        updatemenus=list(view_menu)) %&gt;%
  finish_3d(colours,meta)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Interactive chart: The structures under the cortex</a></p>
</div>
</div>
<p>The glass is a coarse copy of the cortex. The structures are traced from FreeSurfer’s labeled cubes of 1 mm and smoothed a little. Between them lie the ventricles, the subject of the next question.</p>
<hr>
</section>
<section id="what-fills-the-hollows-inside-the-brain" class="level2">
<h2 class="anchored" data-anchor-id="what-fills-the-hollows-inside-the-brain">5. What fills the hollows inside the brain?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22"><pre><code class="language-r">spaces&lt;-ventricle_list[ventricle_list$code!="choroid",]
fluid_volume&lt;-sum(spaces$volume)
lateral&lt;-ventricle_list[ventricle_list$code=="lateral",]
third&lt;-ventricle_list[ventricle_list$code=="third",]
fourth&lt;-ventricle_list[ventricle_list$code=="fourth",]</code></pre></div></div>
</details>
</div>
<p><strong>Fluid: 46.4 cm³ of it, in four ventricles.</strong> The brain is hollow in the middle. Its two <strong>lateral ventricles</strong>, one in each hemisphere, arch from the front of the brain back over the thalamus and then down into the temporal lobe; they hold 22.0 cm³ on the left and 20.2 on the right. Both open into the narrow <strong>third ventricle</strong>, between the two halves of the thalamus (1.9 cm³), which drains through a thin channel, the aqueduct, into the <strong>fourth ventricle</strong>, between the brain stem and the cerebellum (2.2 cm³); from there the fluid flows out around the brain and the spinal cord. Most of it is made by the <strong>choroid plexus</strong>, a fringe of small blood vessels in the ventricles, and it is renewed about four times a day. A living adult has about 150 ml of it, 25 ml of which is in the ventricles (<a href="https://doi.org/10.1016/j.anorl.2011.03.002">Sakka et al.&nbsp;2011</a>); the ventricles of the average brain hold more, and like all its sizes theirs are not those of any one head.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23"><pre><code class="language-r">p&lt;-plot_ly()
for(h in names(hemispheres))
  p&lt;-add_mesh(p,coarse[[h]]$vertices,coarse[[h]]$faces,"Cortex",opacity=0.1,hoverinfo="skip",
              lighting=glass_lighting,showlegend=FALSE)
colours&lt;-c(glass_gray,glass_gray)
meta&lt;-c(NA,NA)
for(k in seq_len(nrow(ventricle_list))) {
  space&lt;-ventricle_list[k,]
  shape&lt;-ventricle_shapes[[space$code]]
  p&lt;-add_mesh(p,shape$vertices,shape$faces,space$name,flatshading=FALSE,lighting=lighting,
              lightposition=above,showlegend=TRUE)
  colours&lt;-c(colours,ventricle_colours[[space$code]])
  meta&lt;-c(meta,pointer_text(space$name,space$role,volume_words(space)))
}
p %&gt;%
  chart("The ventricles, the hollows of the brain",
        paste("FreeSurfer's segmentation of fsaverage (aseg.mgz), from fsbrain's test data.",
              "A click on a name hides it."),
        margin=list(t=60,b=80,l=0,r=0),note_y=0,note_shift=-40,
        scene=scene(list(x=-1.25,y=0.75,z=0.3),list(x=c(0,0.8),y=c(0,1))),
        legend=list(x=1,xanchor="right",y=0.95,itemsizing="constant"),
        updatemenus=list(view_menu)) %&gt;%
  finish_3d(colours,meta)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Interactive chart: The ventricles, the hollows of the brain</a></p>
</div>
</div>
<p>FreeSurfer’s segmentation does not label the aqueduct, so the third and the fourth ventricle look apart here.</p>
<hr>
</section>
<section id="how-are-the-parts-wired-together" class="level2">
<h2 class="anchored" data-anchor-id="how-are-the-parts-wired-together">6. How are the parts wired together?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24"><pre><code class="language-r">longest&lt;-tract_list[which.max(tract_list$length),]
shortest&lt;-tract_list[which.min(tract_list$length),]
arcuate&lt;-tract_list[tract_list$code=="af"&amp;tract_list$side=="left",]
group_count&lt;-table(factor(tract_list$group,levels=names(groups)))
cerebellar&lt;-if(group_count[["cerebellar"]]==1) "one carries signals into the cerebellum" else
  paste(group_count[["cerebellar"]],"carry signals into the cerebellum")</code></pre></div></div>
</details>
</div>
<p><strong>42 bundles in this atlas, from 5 to 15 cm long.</strong> Of them, 9 cross from one hemisphere to the other (the eight parts of the corpus callosum and the anterior commissure), 16 link areas within a hemisphere, 8 run between the cortex and the thalamus or the spinal cord, 8 belong to the circuits of memory and emotion, and one carries signals into the cerebellum. The <strong>arcuate fasciculus</strong>, which joins the speech areas at the front and at the back of the brain, is 114 mm long on the left. The longest of all is the <strong>corticospinal tract</strong>, 149 mm, from the motor cortex down to the bottom of the brain stem, where the atlas ends and the tract goes on down the spinal cord; the shortest the acoustic radiation, 52 mm.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25"><pre><code class="language-r">p&lt;-plot_ly()
for(h in names(hemispheres))
  p&lt;-add_mesh(p,coarse[[h]]$vertices,coarse[[h]]$faces,"Cortex",opacity=0.08,hoverinfo="skip",
              lighting=glass_lighting,showlegend=FALSE)
colours&lt;-c(glass_gray,glass_gray)
meta&lt;-c(NA,NA)
shown&lt;-c()
for(k in order(match(tract_list$group,names(groups)),tract_list$code)) {
  tract&lt;-tract_list[k,]
  line&lt;-as.data.frame(round(10*tract_points[[k]]))
  p&lt;-add_trace(p,data=line,x=~V1,y=~V2,z=~V3,type="scatter3d",mode="lines",
               name=groups[[tract$group]],legendgroup=tract$group,
               showlegend=!tract$group%in%shown,
               line=list(color=group_colours[[tract$group]],width=6))
  shown&lt;-c(shown,tract$group)
  side&lt;-if(tract$side=="middle") "" else paste0(", ",tract$side)
  colours&lt;-c(colours,NA)
  meta&lt;-c(meta,pointer_text(paste0(tract$name,side),tract$role,
                            paste0(number(tract$length)," mm long")))
}
p %&gt;%
  chart("The tracts of white matter, by kind",
        "TRACULA's atlas of white-matter tracts, from ggseg.formats. A click on a kind hides it.",
        margin=list(t=120,b=80,l=0,r=0),note_y=0,note_shift=-40,
        scene=scene(list(x=-1.25,y=0.75,z=0.3)),legend=c(legend_top,list(itemsizing="constant")),
        updatemenus=list(view_menu)) %&gt;%
  finish_3d(colours,meta)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Interactive chart: The tracts of white matter, by kind</a></p>
</div>
</div>
<p>Each line is the middle of a bundle of fibers several millimeters thick, which fans out where it reaches the cortex. The pointer over a line names the tract, says what it carries and how long it is.</p>
<hr>
</section>
<section id="so-what-does-it-mean" class="level2">
<h2 class="anchored" data-anchor-id="so-what-does-it-mean">So, what does it mean?</h2>
<p><strong>The brain is a large sheet packed into a small skull, hollow in the middle and wired across.</strong></p>
<ol type="1">
<li><strong>A folded sheet</strong>: 1,286 cm² of cortex, whose outer surface has 1.7 times the area of the wraps around the hemispheres; 58% of it lies more than 5 mm deep in the folds.</li>
<li><strong>Thin and thick</strong>: from 1.8 mm in the pericalcarine cortex, where the signals of the eyes arrive, to 4.5 mm in the temporal pole.</li>
<li><strong>Small parts with large tasks</strong>: the hippocampus, 5.3 cm³ on each side, makes new memories; the cerebellum, 11% of the brain, holds most of its nerve cells.</li>
<li><strong>Hollow in the middle</strong>: 46.4 cm³ of fluid in four ventricles, made by the choroid plexus and renewed about four times a day.</li>
<li><strong>Wired along and across</strong>: 42 bundles link the lobes within each hemisphere, the two hemispheres with each other, and the cortex with the structures under it and the spinal cord.</li>
</ol>
<p><strong>What this does not show.</strong> The brain is an average of many brains, and smoother than any one of them: averaging blurs the folds, so a real brain has more area and deeper folds than this one, and its parts differ in size and shape from person to person. The regions of the atlas follow the folds, not what the cortex does, and their roles are simplified: each region does more than one thing, and most tasks use many regions. The thickness and the depth are measured on the average surfaces, not averaged over people. The structures under the cortex and the ventricles are traced from FreeSurfer’s labeled cubes of 1 mm and smoothed a little; the tracts come from an atlas with a frame of its own, are laid on the volume as shown under <em>The data</em>, and are the middle lines of their bundles. The volumes are those of the average brain, whose size is set by the template it was laid on, not by any one head.</p>
<p>For how the brain can be fooled by what the eyes see, see <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_ILLUSIONS.html">Illusions in R</a>.</p>
<hr>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<ul>
<li>Azevedo, F.A.C. and others (2009), <a href="https://doi.org/10.1002/cne.21974">Equal numbers of neuronal and nonneuronal cells make the human brain an isometrically scaled-up primate brain</a>, <em>Journal of Comparative Neurology</em> 513, 532–541.</li>
<li>Betts, J.G. and others (2022), <a href="https://openstax.org/books/anatomy-and-physiology-2e/pages/13-2-the-central-nervous-system">Anatomy and Physiology 2e</a>, chapter 13, The Anatomy of the Nervous System, OpenStax: the lobes, the structures under the cortex, the ventricles and what they do.</li>
<li>Catani, M. and Thiebaut de Schotten, M. (2008), <a href="https://doi.org/10.1016/j.cortex.2008.05.004">A diffusion tensor imaging tractography atlas for virtual in vivo dissections</a>, <em>Cortex</em> 44, 1105–1132: the tracts and what they link.</li>
<li>Desikan, R.S. and others (2006), <a href="https://doi.org/10.1016/j.neuroimage.2006.01.021">An automated labeling system for subdividing the human cerebral cortex on MRI scans into gyral based regions of interest</a>, <em>NeuroImage</em> 31, 968–980.</li>
<li>Dick, A.S., Garic, D., Graziano, P. and Tremblay, P. (2019), <a href="https://doi.org/10.1016/j.cortex.2018.10.015">The frontal aslant tract (FAT) and its role in speech, language and executive function</a>, <em>Cortex</em> 111, 148–163.</li>
<li>Epstein, R. and Kanwisher, N. (1998), <a href="https://doi.org/10.1038/33402">A cortical representation of the local visual environment</a>, <em>Nature</em> 392, 598–601: the parahippocampal gyrus and places.</li>
<li>Feng, D. and Tierney, L. (2008), <a href="https://doi.org/10.18637/jss.v028.i01">Computing and displaying isosurfaces in R</a>, <em>Journal of Statistical Software</em> 28(1): misc3d, which traces the surfaces of the structures and the ventricles.</li>
<li>Fischl, B. and Dale, A.M. (2000), <a href="https://doi.org/10.1073/pnas.200033797">Measuring the thickness of the human cerebral cortex from magnetic resonance images</a>, <em>Proceedings of the National Academy of Sciences</em> 97, 11050–11055.</li>
<li>Fischl, B., Sereno, M.I., Tootell, R.B.H. and Dale, A.M. (1999), <a href="https://doi.org/10.1002/(SICI)1097-0193(1999)8%3A4%3C272%3A%3AAID-HBM10%3E3.0.CO%3B2-4">High-resolution intersubject averaging and a coordinate system for the cortical surface</a>, <em>Human Brain Mapping</em> 8, 272–284: fsaverage.</li>
<li>Fischl, B. and others (2002), <a href="https://doi.org/10.1016/S0896-6273(02)00569-X">Whole brain segmentation: automated labeling of neuroanatomical structures in the human brain</a>, <em>Neuron</em> 33, 341–355: the segmentation of the structures under the cortex and of the ventricles.</li>
<li>Kanwisher, N., McDermott, J. and Chun, M.M. (1997), <a href="https://doi.org/10.1523/JNEUROSCI.17-11-04302.1997">The fusiform face area: a module in human extrastriate cortex specialized for face perception</a>, <em>Journal of Neuroscience</em> 17, 4302–4311.</li>
<li>Maffei, C. and others (2021), <a href="https://doi.org/10.1016/j.neuroimage.2021.118706">Using diffusion MRI data acquired with ultra-high gradient strength to improve tractography in routine-quality data</a>, <em>NeuroImage</em> 245, 118706: the 42 tracts of TRACULA.</li>
<li>Mowinckel, A.M. and Vidal-Piñeiro, D. (2020), <a href="https://doi.org/10.1177/2515245920928009">Visualization of brain statistics with R packages ggseg and ggseg3d</a>, <em>Advances in Methods and Practices in Psychological Science</em> 3, 466–483; the surfaces and the atlases come from the packages <a href="https://ggsegverse.github.io/ggseg.formats/">ggseg.formats</a> and <a href="https://ggsegverse.github.io/ggseg.meshes/">ggseg.meshes</a>.</li>
<li>Plotly, <a href="https://brain-viewer.plotly.app/">MRI Reconstruction</a>, a sample app of Dash (<a href="https://github.com/plotly/dash-sample-apps/tree/master/apps/dash-brain-viewer">code on GitHub</a>).</li>
<li>Sakka, L., Coll, G. and Chazal, J. (2011), <a href="https://doi.org/10.1016/j.anorl.2011.03.002">Anatomy and physiology of cerebrospinal fluid</a>, <em>European Annals of Otorhinolaryngology, Head and Neck Diseases</em> 128, 309–316.</li>
<li>Schäfer, T. and Ecker, C. (2020), <a href="https://doi.org/10.1101/2020.09.18.302935">fsbrain: an R package for the visualization of structural neuroimaging data</a>, <em>bioRxiv</em>: its server keeps the copy of FreeSurfer’s segmentation of fsaverage that the page downloads.</li>
<li>Yendiki, A. and others (2011), <a href="https://doi.org/10.3389/fninf.2011.00023">Automated probabilistic reconstruction of white-matter pathways in health and disease using an atlas of the underlying anatomy</a>, <em>Frontiers in Neuroinformatics</em> 5, 23: TRACULA.</li>
</ul>
<hr>
</section>
<section id="acknowledgments" class="level2">
<h2 class="anchored" data-anchor-id="acknowledgments">Acknowledgments</h2>
<p>The average brain, the atlas of its regions, its segmentation and the atlas of its tracts come from <a href="https://surfer.nmr.mgh.harvard.edu/">FreeSurfer</a>. The surfaces drawn on this page are modified from FreeSurfer’s: they are turned and moved into one frame, cut into regions, simplified and, for the structures under the cortex and the ventricles, traced from the labeled volume; they are not FreeSurfer’s original files. The surfaces of the cortex and the atlases come from the R packages ggseg.formats and ggseg.meshes, © 2026 their authors, under the MIT license, and the copy of the segmentation from the server of the fsbrain package. The idea of a brain that turns under the mouse comes from Plotly’s <a href="https://brain-viewer.plotly.app/">MRI Reconstruction</a> app.</p>
<p>All or portions of this licensed product (such portions are the “Software”) have been obtained under license from The General Hospital Corporation “MGH” and are subject to the following terms and conditions:</p>
<details>
<summary>
The FreeSurfer Software License Agreement, version 1.0 (February 2011), part B
</summary>
<pre class="text"><code>PART B. DOWNLOADING AGREEMENT - License from MGH with Right to Sublicense
("Software License").
1. As used in this Software License, "you" means the individual
   downloading and/or using, reproducing, modifying, displaying and/or
   distributing the Software and the institution or entity which
   employs or is otherwise affiliated with such individual in
   connection therewith. The General Hospital Corporation ("MGH")
   hereby grants you, with right to sublicense, with
   respect to MGH's rights in the software, and data, if any,
   which is the subject of this Software License (collectively, the
   "Software"), a royalty-free, non-exclusive license to use,
   reproduce, make derivative works of, display and distribute the
   Software, provided that:
(a) you accept and adhere to all of the terms and conditions of this
Software License;
(b) in connection with any copy of or sublicense of all or any portion
of the Software, all of the terms and conditions in this Software
License shall appear in and shall apply to such copy and such
sublicense, including without limitation all source and executable
forms and on any user documentation, prefaced with the following
words: "All or portions of this licensed product (such portions are
the "Software") have been obtained under license from The General Hospital
Corporation "MGH" and are subject to the following terms and
conditions:"
(c) you preserve and maintain all applicable attributions, copyright
notices and licenses included in or applicable to the Software;
(d) modified versions of the Software must be clearly identified and
marked as such, and must not be misrepresented as being the original
Software; and
(e) you consider making, but are under no obligation to make, the
source code of any of your modifications to the Software freely
available to others on an open source basis.
2. The license granted in this Software License includes without
   limitation the right to (i) incorporate the Software into
   proprietary programs (subject to any restrictions applicable to
   such programs), (ii) add your own copyright statement to your
   modifications of the Software, and (iii) provide additional or
   different license terms and conditions in your sublicenses of
   modifications of the Software; provided that in each case your use,
   reproduction or distribution of such modifications otherwise
   complies with the conditions stated in this Software License.
3. This Software License does not grant any rights with respect to
   third party software, except those rights that MGH has been
   authorized by a third party to grant to you, and accordingly you
   are solely responsible for (i) obtaining any permissions from third
   parties that you need to use, reproduce, make derivative works of,
   display and distribute the Software, and (ii) informing your
   sublicensees, including without limitation your end-users, of their
   obligations to secure any such required permissions.
4. The Software has been designed for research purposes only and has
   not been reviewed or approved by the Food and Drug Administration
   or by any other agency. YOU ACKNOWLEDGE AND AGREE THAT CLINICAL
   APPLICATIONS ARE NEITHER RECOMMENDED NOR ADVISED. Any
   commercialization of the Software is at the sole risk of the party
   or parties engaged in such commercialization. You further agree to
   use, reproduce, make derivative works of, display and distribute
   the Software in compliance with all applicable governmental laws,
   regulations and orders, including without limitation those relating
   to export and import control.
5. The Software is provided "AS IS" and neither MGH nor any
   contributor to the software (each a "Contributor") shall have any
   obligation to provide maintenance, support, updates, enhancements
   or modifications thereto. MGH AND ALL CONTRIBUTORS SPECIFICALLY
   DISCLAIM ALL EXPRESS AND IMPLIED WARRANTIES OF ANY KIND INCLUDING,
   BUT NOT LIMITED TO, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR
   A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
   MGH OR ANY CONTRIBUTOR BE LIABLE TO ANY PARTY FOR DIRECT,
   INDIRECT, SPECIAL, INCIDENTAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES
   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY ARISING IN ANY WAY
   RELATED TO THE SOFTWARE, EVEN IF MGH OR ANY CONTRIBUTOR HAS
   BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. TO THE MAXIMUM
   EXTENT NOT PROHIBITED BY LAW OR REGULATION, YOU FURTHER ASSUME ALL
   LIABILITY FOR YOUR USE, REPRODUCTION, MAKING OF DERIVATIVE WORKS,
   DISPLAY, LICENSE OR DISTRIBUTION OF THE SOFTWARE AND AGREE TO
   INDEMNIFY AND HOLD HARMLESS MGH AND ALL CONTRIBUTORS FROM AND
   AGAINST ANY AND ALL CLAIMS, SUITS, ACTIONS, DEMANDS AND JUDGMENTS
   ARISING THEREFROM.
6. None of the names, logos or trademarks of MGH or any of
   MGH's affiliates or any of the Contributors, or any funding
   agency, may be used to endorse or promote products produced in
   whole or in part by operation of the Software or derived from or
   based on the Software without specific prior written permission
   from the applicable party.
7. Any use, reproduction or distribution of the Software which is not
   in accordance with this Software License shall automatically revoke
   all rights granted to you under this Software License and render
   Paragraphs 1 and 2 of this Software License null and void.
8. This Software License does not grant any rights in or to any
   intellectual property owned by MGH or any Contributor except
   those rights expressly granted hereunder.</code></pre>
</details>
<p>The whole agreement is on <a href="https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferSoftwareLicense">FreeSurfer’s website</a>.</p>
<hr>
<p><em>Rendered with R 4.6.2 · plotly · ggseg.formats · ggseg.meshes · freesurferformats · misc3d · geometry</em></p>
<!-- -->
</section>
<p>This post first appeared on <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_BRAIN.html">Illustrations in R</a>, with its interactive charts and the full R code.</p>]]></content:encoded>
    </item>
    <item>
      <title>Is Athens Running Out of Water? The Reservoirs of Attica Since 1985</title>
      <link>https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_ATHENS_WATER.html</link>
      <guid isPermaLink="true">https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_ATHENS_WATER.html</guid>
      <pubDate>Sun, 29 Nov 2026 16:25:46 +0200</pubDate>
      <category>R</category>
      <category>Illustrations in R</category>
      <description>EYDAP’s water reserves of Mornos, Yliki, Evinos and Marathon on every day since 1985: how much water Athens has now, how low it fell in 2025 and in the drought of the early 1990s, how the reservoirs fill in the winter and empty in the summer, and how much of that depends on the rain.</description>
      <content:encoded><![CDATA[<p><em>EYDAP’s water reserves of Mornos, Yliki, Evinos and Marathon on every day since 1985: how much water Athens has now, how low it fell in 2025 and in the drought of the early 1990s, how the reservoirs fill in the winter and empty in the summer, and how much of that depends on the rain.</em></p>
<p><img src="https://sedzinfo.github.io/vignettes/illustration/social-card.png" alt="Illustrations in R" width="1200" height="630"></p>
<section id="what-is-this" class="level2">
<h2 class="anchored" data-anchor-id="what-is-this">What is this?</h2>
<p>Most of the water of Athens comes from four reservoirs: Mornos and Evinos in the mountains of central Greece, the lake of Yliki in Boeotia, and Marathon, near the city. After three dry winters they held less water in the autumn of 2025 than they had for more than twenty years, and on 28 November 2025 the government declared Attica in a state of drought emergency (<a href="https://www.tovima.com/stories/athens-enters-drought-emergency-as-water-reserves-collapse/">Tratsa 2025</a>). This data story looks at the reserves of every day since 1985, with five questions:</p>
<ol type="1">
<li><strong>How much water is there now?</strong></li>
<li><strong>Has it been this low before?</strong></li>
<li><strong>When do the reservoirs fill and empty?</strong></li>
<li><strong>Was it the summers or the winters?</strong></li>
<li><strong>Was it the rain?</strong></li>
</ol>
<p>The reserves come from <strong>EYDAP</strong>, the water company of Athens, which publishes those of each reservoir every day. <strong>iMEdD Lab</strong>, a Greek journalism lab, has collected them back to 1 January 1985 and keeps them up to date on GitHub (<a href="https://lab.imedd.org/en/water-reserves-in-attica-from-1985-to-the-present-day/">Marinou 2025</a>; <a href="https://lab.imedd.org/en/the-water-reserves-of-attica-in-live-charts-that-update-daily/">Methodios 2026</a>). The rain comes from <strong>ERA5</strong>, the reconstruction of the weather of every day since 1940 by the European Centre for Medium-Range Weather Forecasts (<a href="https://doi.org/10.1002/qj.3803">Hersbach et al.&nbsp;2020</a>). Both are downloaded when the page is rendered, so a new render brings in the latest days.</p>
<p><strong>The words of this page:</strong></p>
<ul>
<li>the <strong>reserves</strong> are what EYDAP calls the <em>extractable reserves</em>: the water that can be drawn from the reservoirs, in million cubic meters (million m³). A million m³ would fill a cube 100 meters on each side;</li>
<li>a <strong>wet season</strong> runs from the autumn to the spring, and is named by its two years: 2025–26 is the autumn of 2025 and the spring of 2026. Its <strong>rise</strong> goes from the lowest reserves of the autumn or winter to the highest of the spring or summer after, and the <strong>fall</strong> of the dry season after it goes from that high to the next low.</li>
</ul>
<hr>
</section>
<section id="packages" class="level2">
<h2 class="anchored" data-anchor-id="packages">Packages</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1"><pre><code class="language-r"># install.packages("plotly")
library(plotly)</code></pre></div></div>
</details>
</div>
</section>
<section id="the-data" class="level2">
<h2 class="anchored" data-anchor-id="the-data">The data</h2>
<section id="the-reserves" class="level3">
<h3 class="anchored" data-anchor-id="the-reserves">The reserves</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2"><pre><code class="language-r"># the lines of a file on the web, tried again a few times: the servers sometimes refuse a connection
# or take too long to answer
read_lines&lt;-function(url,tries=4) {
  for(k in seq_len(tries)) {
    result&lt;-tryCatch(readLines(url,warn=FALSE),error=function(e) NULL)
    if(!is.null(result))
      return(result)
    Sys.sleep(10)
  }
  stop("Could not download ",url)
}
# the reserves of the four reservoirs on every day since 1 January 1985, in cubic meters, as EYDAP
# publishes them, from the copy that iMEdD Lab keeps on GitHub and brings up to date every working
# day. Its column Total is EYDAP's total of the four
github&lt;-"https://raw.githubusercontent.com/iMEdD-Lab/eydap_water_reserves/main/"
raw&lt;-read.csv(text=read_lines(paste0(github,"water_reserves_latest.csv")))
raw$Date&lt;-as.Date(raw$Date)
raw&lt;-raw[order(raw$Date),]
# the reservoirs by their names in English, from the largest to the smallest
reservoirs&lt;-c(Mornos="Mornos",Yliki="Yliki",Eyinos="Evinos",Marathonas="Marathon")
# a reading that stands out from the days on either side by more than 3 million m³ while those two
# agree with each other: a slip, such as Mornos on 25 July 2019, 326 million m³ between 627 and 625.
# A real rise or fall does not undo itself the next day
is_slip&lt;-function(x,limit=3e6) {
  n&lt;-length(x)
  from_before&lt;-c(NA,diff(x))
  from_after&lt;-c(-diff(x),NA)
  across&lt;-c(NA,x[3:n]-x[1:(n-2)],NA)
  result&lt;-!is.na(from_before)&amp;!is.na(from_after)&amp;abs(from_before)&gt;limit&amp;abs(from_after)&gt;limit&amp;
    sign(from_before)==sign(from_after)&amp;abs(across)&lt;pmin(abs(from_before),abs(from_after))/2
  return(result)
}
# every day from the first to the last, in million m³: the slips and the days missing from the
# record are filled in from the days on either side
days&lt;-data.frame(date=seq(min(raw$Date),max(raw$Date),by="day"))
slips&lt;-0
for(k in names(reservoirs)) {
  slip&lt;-is_slip(raw[[k]])
  slips&lt;-slips+sum(slip)
  days[[reservoirs[[k]]]]&lt;-approx(as.numeric(raw$Date[!slip]),raw[[k]][!slip]/1e6,
                                  xout=as.numeric(days$date))$y
}
missing_days&lt;-nrow(days)-nrow(raw)
# the total is the sum of the four: EYDAP's own total differs from it on a few hundred days, by a
# few million m³ at most apart from its own slips
days$total&lt;-rowSums(days[,reservoirs])
days$year&lt;-as.integer(format(days$date,"%Y"))
last&lt;-max(days$date)
this_year&lt;-as.integer(format(last,"%Y"))
now&lt;-days$total[days$date==last]</code></pre></div></div>
</details>
</div>
<p>The record has 17 missing days and 28 readings that are slips, such as the day on which Mornos held half as much as on the days on either side; the page fills them in from the days around them.</p>
</section>
<section id="the-rise-and-fall-of-every-season" class="level3">
<h3 class="anchored" data-anchor-id="the-rise-and-fall-of-every-season">The rise and fall of every season</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3"><pre><code class="language-r"># a wet season by its two years: 2025–26, 1999–2000
season_name&lt;-function(year) {
  result&lt;-ifelse(year%%100==0,paste0(year-1,"–",year),paste0(year-1,"–",sprintf("%02d",year%%100)))
  return(result)
}
# the low of the wet season whose spring is in a year: the lowest reserves from 1 September of the
# year before to the end of February
season_low&lt;-function(year) {
  x&lt;-days[days$date&gt;=as.Date(paste0(year-1,"-09-01"))&amp;days$date&lt;as.Date(paste0(year,"-03-01")),]
  result&lt;-x[which.min(x$total),c("date","total")]
  return(result)
}
# every wet season since 1985–86 whose low is known: its low, its high (the highest reserves from
# the low to 31 July) and its rise; a season whose high may still come is not over
seasons&lt;-data.frame()
for(year in (min(days$year)+1):this_year) {
  if(last&lt;as.Date(paste0(year,"-02-28")))
    next
  low&lt;-season_low(year)
  x&lt;-days[days$date&gt;=low$date&amp;days$date&lt;as.Date(paste0(year,"-08-01")),]
  seasons&lt;-rbind(seasons,data.frame(year=year,low_date=low$date,low=low$total,
                                    high_date=x$date[which.max(x$total)],high=max(x$total),
                                    rise_over=last&gt;=as.Date(paste0(year,"-07-31"))))
}
seasons$rise&lt;-seasons$high-seasons$low
seasons$name&lt;-season_name(seasons$year)
# the fall from each high to the low of the next season; the last fall goes to the lowest reserves
# since its high, as its dry season is not over
n&lt;-nrow(seasons)
seasons$fall&lt;-seasons$high-c(seasons$low[-1],min(days$total[days$date&gt;=seasons$high_date[n]]))
seasons$fall_over&lt;-c(rep(TRUE,n-1),FALSE)</code></pre></div></div>
</details>
</div>
</section>
<section id="the-rain" class="level3">
<h3 class="anchored" data-anchor-id="the-rain">The rain</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4"><pre><code class="language-r"># the rain of every day since October 1985 over the mountains of the Evinos and the Mornos, where
# most of the water comes from: the mean of six points of the grid of ERA5, a quarter of a degree
# apart (38.5° and 38.75° N, 21.75° to 22.25° E), through Open-Meteo, as one CSV file: the points,
# an empty line, then the days. Snow counts as the water it holds
rain_url&lt;-paste0("https://archive-api.open-meteo.com/v1/archive",
                 "?latitude=38.5,38.5,38.5,38.75,38.75,38.75",
                 "&amp;longitude=21.75,22,22.25,21.75,22,22.25&amp;start_date=1985-10-01",
                 "&amp;end_date=",Sys.Date()-1,"&amp;daily=precipitation_sum",
                 "&amp;timezone=Europe%2FAthens&amp;models=era5&amp;format=csv")
lines&lt;-read_lines(rain_url)
rain&lt;-read.csv(text=lines[-seq_len(which(lines=="")[1])],col.names=c("point","date","mm"))
rain&lt;-rain[!is.na(rain$mm),] # the last few days are not ready yet
rain&lt;-aggregate(mm~date,rain,mean)
rain$date&lt;-as.Date(rain$date)
rain$month&lt;-as.integer(format(rain$date,"%m"))
# the year of a day from October to September, named by the year of its spring
rain$season&lt;-as.integer(format(rain$date,"%Y"))+(rain$month&gt;=10)
wet&lt;-rain$month%in%c(10:12,1:4)
# the rain of each wet season, October to April; none for a season whose rain is not all in yet
seasons$rain&lt;-as.vector(tapply(rain$mm[wet],rain$season[wet],sum)[as.character(seasons$year)])
seasons$rain[max(rain$date)&lt;as.Date(paste0(seasons$year,"-04-30"))]&lt;-NA
# the share of the rain of the whole years, October to September, that falls from October to April
whole&lt;-rain$season&lt;as.integer(format(max(rain$date)+1,"%Y"))+(format(max(rain$date)+1,"%m")&gt;="10")
wet_share&lt;-100*sum(rain$mm[whole&amp;wet])/sum(rain$mm[whole])
# how the rise of a season follows its rain: the straight line that fits best the seasons that are
# over and whose rain is known, and the rise it predicts for each of them
known&lt;-seasons[seasons$rise_over&amp;!is.na(seasons$rain),]
fit&lt;-lm(rise~rain,known)
slope&lt;-coef(fit)[["rain"]]
known$expected&lt;-predict(fit)</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5"><pre><code class="language-r">greek_red&lt;-"#d62728"
blue&lt;-"#1f77b4"
gold&lt;-"#c47f17"
gray&lt;-"#9e9e9e"
ring_gray&lt;-"#d4d4d4"
light_gray&lt;-"#ececec"
dark_gray&lt;-"#6b6b6b" # also the color of the notes and the labels
# the reservoirs, told apart also by color-blind readers (every pair checked)
reservoir_colours&lt;-c(Mornos=blue,Yliki="#17becf",Evinos=gold,Marathon="#7f7f7f")
# the source of a chart, as a note under it, and the common layout
chart&lt;-function(p,title,source,y_title="",y_axis=list(),x_axis=list(),annotations=list(),
                margin=list(t=70,b=90),note_y=-0.16,...) {
  note&lt;-list(text=paste("Source:",source),xref="paper",yref="paper",x=0,y=note_y,xanchor="left",
             yanchor="top",align="left",showarrow=FALSE,font=list(size=11,color=dark_gray))
  result&lt;-layout(p,
                 title=list(text=title,x=0.02,xanchor="left",y=0.97,yanchor="top"),
                 yaxis=modifyList(list(title=y_title),y_axis),
                 xaxis=modifyList(list(title=""),x_axis),
                 margin=margin,
                 annotations=c(annotations,list(note)),
                 ...) %&gt;%
    config(displaylogo=FALSE)
  return(result)
}
legend_top&lt;-list(orientation="h",x=0,y=1.02,yanchor="bottom")
eydap&lt;-"EYDAP, through iMEdD Lab."
# a label with a line to a point of a chart, on white so that it can be read over a colored area:
# the number in bold and the month under it
point_label&lt;-function(date,value,ax=0,ay=-40) {
  result&lt;-list(x=date,y=value,text=paste0("&lt;b&gt;",number(value),"&lt;/b&gt;&lt;br&gt;",format(date,"%b %Y")),
               showarrow=TRUE,arrowhead=0,arrowcolor=dark_gray,ax=ax,ay=ay,
               bgcolor="rgba(255,255,255,0.85)",borderpad=2,font=list(size=12,color=dark_gray))
  return(result)
}
# short labels of numbers, dates and lists
number&lt;-function(x) {
  result&lt;-format(round(x),big.mark=",",trim=TRUE)
  return(result)
}
two&lt;-function(x) {
  result&lt;-format(round(x,2),nsmall=2,trim=TRUE)
  return(result)
}
percent&lt;-function(x) {
  result&lt;-paste0(round(x),"%")
  return(result)
}
date_text&lt;-function(x) {
  result&lt;-trimws(format(x,"%e %B %Y"))
  return(result)
}
month_text&lt;-function(x) {
  result&lt;-format(x,"%B %Y")
  return(result)
}
ordinal&lt;-function(n) {
  suffix&lt;-ifelse(n%%100%in%11:13,"th",c("th","st","nd","rd",rep("th",6))[n%%10+1])
  result&lt;-paste0(n,suffix)
  return(result)
}
and_list&lt;-function(x,last_word="and") {
  result&lt;-if(length(x)&lt;2) paste(x) else paste(paste(x[-length(x)],collapse=", "),last_word,
                                               x[length(x)])
  return(result)
}
# years as runs: 1989–1995, 2001–2002 and 2008
year_runs&lt;-function(years) {
  years&lt;-sort(years)
  starts&lt;-years[c(TRUE,diff(years)&gt;1)]
  ends&lt;-years[c(diff(years)&gt;1,TRUE)]
  result&lt;-and_list(ifelse(starts==ends,starts,paste0(starts,"–",ends)))
  return(result)
}
# "58% more than" or "34% less than"
compared&lt;-function(x,base) {
  change&lt;-round(100*(x/base-1))
  result&lt;-if(change&gt;=0) paste0(change,"% more than") else paste0(-change,"% less than")
  return(result)
}</code></pre></div></div>
</details>
</div>
<hr>
</section>
</section>
<section id="how-much-water-is-there-now" class="level2">
<h2 class="anchored" data-anchor-id="how-much-water-is-there-now">1. How much water is there now?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6"><pre><code class="language-r"># the reserves on the same day of every year
same_day&lt;-days[format(days$date,"%m-%d")==format(last,"%m-%d"),c("year","total")]
year_before&lt;-same_day$total[same_day$year==this_year-1]
# the years since the Evinos reservoir began to fill, at the end of 2001
evinos_years&lt;-same_day[same_day$year&gt;=2002&amp;same_day$year&lt;this_year,]
usual&lt;-mean(evinos_years$total)
lower&lt;-same_day$year[same_day$total&lt;now]
most&lt;-length(lower)&lt;(nrow(same_day)-1)/2 # less water than in most of the years before
lead_now&lt;-paste0(if(now&gt;year_before) "More than a year ago, " else "Less than a year ago, ",
                 if(most==(now&gt;year_before)) "but " else "and ",
                 if(most) "less than in most years." else "more than in most years.")</code></pre></div></div>
</details>
</div>
<p><strong>More than a year ago, but less than in most years.</strong> On 27 November 2026, the last day of the data, the four reservoirs held <strong>576 million m³</strong>: 58% more than on the same day of 2025, and 36% less than the average of that day in 2002–2025, the years since the Evinos reservoir began to fill. There was less water on this day in 12 of the 41 years before: 1989–1995, 2001–2002, 2008 and 2024–2025.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7"><pre><code class="language-r">same_day$colour&lt;-ifelse(same_day$year==this_year,greek_red,gray)
plot_ly(same_day,x=~year,y=~total,type="bar",marker=list(color=same_day$colour),
        hovertemplate="%{x}: %{y:,.0f} million m³&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  chart(paste0("The reserves on ",trimws(format(last,"%e %B"))," of every year, million m³"),
        paste(eydap,"The dotted line: the reserves of",date_text(last)),
        "million m³",
        shapes=list(list(type="line",xref="paper",x0=0,x1=1,y0=now,y1=now,
                         line=list(color=dark_gray,width=1,dash="dot"))))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_ATHENS_WATER.html">Interactive chart: The reserves on 27 November of every year, million m³</a></p>
</div>
</div>
<hr>
</section>
<section id="has-it-been-this-low-before" class="level2">
<h2 class="anchored" data-anchor-id="has-it-been-this-low-before">2. Has it been this low before?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8"><pre><code class="language-r">lowest&lt;-days[which.min(days$total),]
highest&lt;-days[which.max(days$total),]
yliki_lowest&lt;-days[which.min(days$Yliki),]
# the lowest reserves since the Evinos began to fill, and the last day before them with less
recent&lt;-days[days$year&gt;=2002,]
recent_low&lt;-recent[which.min(recent$total),]
less_before&lt;-max(days$date[days$date&lt;recent_low$date&amp;days$total&lt;recent_low$total])
# the high of the three years before that low, and the low of the dry years 2007-2009
before_low&lt;-recent[recent$date&lt;recent_low$date&amp;recent$date&gt;=recent_low$date-3*365,]
high_before&lt;-before_low[which.max(before_low$total),]
dry_years&lt;-days[days$year%in%2007:2009,]
dry_low&lt;-dry_years[which.min(dry_years$total),]</code></pre></div></div>
</details>
</div>
<p><strong>Yes: lower still, in the drought of the early 1990s.</strong> The reserves were lowest on 13 November 1993: <strong>105 million m³</strong>, 7% of their highest, 1,428 on 25 March 2006. In August 1993, Yliki held only 3 million m³.</p>
<p>In 2025 they fell to <strong>363 million m³</strong>, on 25 November: the lowest since December 2001, when the Evinos reservoir had only just been built, and lower than in the dry years 2007–2009, when they fell to 419 in December 2008. They had lost 67% of their water since March 2023, when they held 1,110 million m³.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9"><pre><code class="language-r"># every seventh day, which is enough for forty years on a screen, the days of the labels and the
# last day
marks&lt;-match(c(lowest$date,recent_low$date,highest$date),days$date)
weekly&lt;-days[sort(unique(c(seq(1,nrow(days),by=7),marks,nrow(days)))),]
p&lt;-plot_ly()
for(k in reservoirs) {
  x&lt;-data.frame(date=weekly$date,value=round(weekly[[k]],1))
  p&lt;-p %&gt;%
    add_trace(data=x,x=~date,y=~value,type="scatter",mode="lines",stackgroup="reserves",name=k,
              line=list(color=reservoir_colours[[k]],width=0.5),fillcolor=reservoir_colours[[k]])
}
# one hover text for each line, with its name; given to add_trace(), it would be repeated for every
# point
p&lt;-style(p,hovertemplate="%{fullData.name}, %{x|%-d %b %Y}: %{y:,.0f} million m³&lt;extra&gt;&lt;/extra&gt;")
# the label of the last low goes to the right, beyond the end of the data
p %&gt;%
  chart("The reserves of the four reservoirs, million m³",
        paste(eydap,"Every seventh day. The Evinos reservoir began to fill at the end of 2001."),
        "million m³",x_axis=list(range=c(min(days$date),last)),
        legend=c(legend_top,list(traceorder="normal")),margin=list(t=100,b=90,r=90),
        annotations=list(point_label(lowest$date,lowest$total,ay=-70),
                         point_label(recent_low$date,recent_low$total,ax=45,ay=-45),
                         point_label(highest$date,highest$total,ax=-50,ay=-20)))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_ATHENS_WATER.html">Interactive chart: The reserves of the four reservoirs, million m³</a></p>
</div>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10"><pre><code class="language-r">shares&lt;-100*unlist(days[days$date==last,reservoirs])/now
evinos_top&lt;-recent[which.max(recent$Evinos),]
# Yliki on the same day of every year, and the last year before with less
yliki_day&lt;-days[format(days$date,"%m-%d")==format(last,"%m-%d"),c("year","Yliki")]
yliki_now&lt;-yliki_day$Yliki[yliki_day$year==this_year]
yliki_less&lt;-yliki_day$year[yliki_day$year&lt;this_year&amp;yliki_day$Yliki&lt;yliki_now]
yliki_top&lt;-days[days$year&gt;=2015,]
yliki_top&lt;-yliki_top[which.max(yliki_top$Yliki),]</code></pre></div></div>
</details>
</div>
<p>Most of the water is in <strong>Mornos</strong>: 70% of it on 27 November 2026. Its reservoir, behind a dam on the river Mornos, began to fill in 1979 (<a href="https://www.eydap.gr/en/TheCompany/Water/WaterSources/">EYDAP</a>). The <strong>Evinos</strong> reservoir, in the mountains to the west, was finished in 2001 to strengthen Mornos. A tunnel takes its water on to Mornos, so it never holds much: 119 million m³ at most, in February 2015. <strong>Yliki</strong> is a natural lake, lower than Athens, whose water has to be pumped up: EYDAP keeps it for emergencies. It held 585 million m³ in April 2020 and 142 on 27 November 2026, its least on this day of the year since 2001. <strong>Marathon</strong>, near the city, holds the least, 3%: it is a reserve and evens out the flow from the others (EYDAP).</p>
<hr>
</section>
<section id="when-do-the-reservoirs-fill-and-empty" class="level2">
<h2 class="anchored" data-anchor-id="when-do-the-reservoirs-fill-and-empty">3. When do the reservoirs fill and empty?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11"><pre><code class="language-r"># the two months in which the highs and the lows of the seasons came most often
top_months&lt;-function(dates) {
  counts&lt;-sort(table(as.integer(format(dates,"%m"))),decreasing=TRUE)[1:2]
  result&lt;-list(names=and_list(month.name[sort(as.integer(names(counts)))],"or"),count=sum(counts))
  return(result)
}
over&lt;-seasons[seasons$rise_over,]
high_months&lt;-top_months(over$high_date)
low_months&lt;-top_months(seasons$low_date)
no_rise&lt;-seasons$year[seasons$rise&lt;1]</code></pre></div></div>
</details>
</div>
<p><strong>They fill in the winter and empty from the spring.</strong> Over the mountains of the Evinos and the Mornos, 73% of the rain falls from October to April. So the reserves rise from the autumn to the spring, and fall for the rest of the year: since 1985–86, their high came in April or May in 31 of the 41 wet seasons, and their low in November or December in 33 of 41. In 1989–90 and 2000–01 they did not rise at all: they fell all winter.</p>
<p>In the chart, every year is a ring around the calendar, with 1 January at the top and the months going clockwise: the further from the center, the more water. The rings of the early 1990s lie close to the center; those of 2003 to 2022, far out.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12"><pre><code class="language-r"># the angle of a day on the ring of its year, in degrees: 1 January at 0, the next 1 January at 360
angle&lt;-function(date) {
  start&lt;-as.Date(paste0(format(date,"%Y"),"-01-01"))
  end&lt;-as.Date(paste0(as.integer(format(date,"%Y"))+1,"-01-01"))
  result&lt;-360*as.numeric(date-start)/as.numeric(end-start)
  return(result)
}
low_year&lt;-as.integer(format(lowest$date,"%Y"))
marked&lt;-data.frame(year=c(this_year,this_year-1,low_year),
                   name=c(paste(this_year,"so far"),this_year-1,paste0(low_year,", the lowest")),
                   colour=c(greek_red,blue,"#333333"),width=c(3,2.5,2.5))
marked&lt;-marked[!duplicated(marked$year),]
others&lt;-setdiff(sort(unique(days$year)),marked$year)
p&lt;-plot_ly()
for(year in c(others,rev(marked$year))) {
  # each ring ends on the first day of the next year, so that it closes
  x&lt;-days[days$year==year|days$date==as.Date(paste0(year+1,"-01-01")),]
  ring&lt;-data.frame(r=round(x$total,1),theta=round(ifelse(x$year&gt;year,360,angle(x$date)),2),
                   day=trimws(format(x$date,"%e %b %Y")))
  m&lt;-match(year,marked$year)
  p&lt;-p %&gt;%
    add_trace(data=ring,r=~r,theta=~theta,text=~day,type="scatterpolar",mode="lines",
              name=if(is.na(m)) "Other years" else marked$name[m],
              legendgroup=if(is.na(m)) "others" else marked$name[m],
              showlegend=is.na(m)&amp;year==others[1]|!is.na(m),
              line=list(color=if(is.na(m)) ring_gray else marked$colour[m],
                        width=if(is.na(m)) 1 else marked$width[m]))
}
p&lt;-style(p,hovertemplate="%{text}: %{r:,.0f} million m³&lt;extra&gt;&lt;/extra&gt;")
firsts&lt;-as.Date(paste0("2001-",1:12,"-01"))
p %&gt;%
  chart("Every year of the reserves around the calendar, million m³",
        paste(eydap,"Each ring is a year; the further from the centre, the more water."),
        x_axis=list(visible=FALSE),y_axis=list(visible=FALSE),
        legend=c(legend_top,list(traceorder="reversed")),margin=list(t=110,b=70),note_y=-0.06,
        polar=list(domain=list(x=c(0.07,0.93),y=c(0,0.93)),
                   angularaxis=list(rotation=90,direction="clockwise",tickvals=angle(firsts),
                                    ticktext=month.abb,gridcolor=light_gray,linecolor=gray),
                   radialaxis=list(range=c(0,ceiling(max(days$total)/100)*100),angle=90,
                                   tickangle=90,gridcolor=light_gray,linecolor=gray,
                                   tickfont=list(size=10,color=dark_gray))))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_ATHENS_WATER.html">Interactive chart: Every year of the reserves around the calendar, million m³</a></p>
</div>
</div>
<hr>
</section>
<section id="was-it-the-summers-or-the-winters" class="level2">
<h2 class="anchored" data-anchor-id="was-it-the-summers-or-the-winters">4. Was it the summers or the winters?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13"><pre><code class="language-r">falls&lt;-seasons[seasons$fall_over,]
three&lt;-seasons[seasons$year%in%2023:2025,]
biggest&lt;-over[which.max(over$rise),]</code></pre></div></div>
</details>
</div>
<p><strong>The winters.</strong> The fall of a dry season changes little from year to year: 271 million m³ on average since 1985–86, and between 233 and 319 in half of them. It is the water that Athens takes and the water that evaporates, less what still flows in. The fall of 2025, the last one that is over, was 306 million m³.</p>
<p>The rise of a wet season changes much more: from nothing in 1989–90 and 2000–01 to 780 million m³ in 2002–03. The three wet seasons from 2022–23 to 2024–25 brought 242 million m³ together, less than one average season, 260.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14"><pre><code class="language-r">ticks&lt;-seasons$year[seasons$year%%5==0]
plot_ly() %&gt;%
  add_bars(data=seasons,x=~year,y=~round(rise,1),name="Rise in the wet season",text=~name,
           textposition="none",marker=list(color=ifelse(seasons$rise_over,blue,"#9dc3e6")),
           hovertemplate="%{text}: up by %{y:,.0f} million m³&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  add_bars(data=seasons,x=~year,y=~round(-fall,1),name="Fall in the dry season after it",
           text=~paste0(year,ifelse(fall_over,""," so far")),textposition="none",
           marker=list(color=ifelse(seasons$fall_over,greek_red,"#f2a5a5")),
           hovertemplate="%{text}: down by %{customdata:,.0f} million m³&lt;extra&gt;&lt;/extra&gt;",
           customdata=~round(fall,1)) %&gt;%
  chart("The rise of every wet season and the fall after it, million m³",
        paste(eydap,"Paler: not over yet. The dotted lines: the averages of the seasons."),
        "million m³",
        x_axis=list(tickvals=ticks,ticktext=season_name(ticks)),
        barmode="relative",legend=legend_top,margin=list(t=100,b=90),
        shapes=list(list(type="line",xref="paper",x0=0,x1=1,y0=mean(over$rise),
                         y1=mean(over$rise),line=list(color=blue,width=1,dash="dot")),
                    list(type="line",xref="paper",x0=0,x1=1,y0=-mean(falls$fall),
                         y1=-mean(falls$fall),line=list(color=greek_red,width=1,dash="dot"))))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_ATHENS_WATER.html">Interactive chart: The rise of every wet season and the fall after it, million m³</a></p>
</div>
</div>
<hr>
</section>
<section id="was-it-the-rain" class="level2">
<h2 class="anchored" data-anchor-id="was-it-the-rain">5. Was it the rain?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15"><pre><code class="language-r">correlation&lt;-cor(known$rise,known$rain)
dry&lt;-known[known$rain&lt;500,]
latest&lt;-known[nrow(known),]
wettest&lt;-rank(-known$rain)[nrow(known)]
# the seasons since 2022-23, and the first four of the record, against the line
recent_seasons&lt;-known[known$year&gt;=2023,]
short&lt;-recent_seasons$expected-recent_seasons$rise
first_four&lt;-known[1:4,]</code></pre></div></div>
</details>
</div>
<p><strong>Mostly.</strong> The more it rained over the mountains of the Evinos and the Mornos from October to April, the more the reserves rose: across the 41 wet seasons since 1985–86 the two have a correlation of 0.84, and every 100 mm more rain brought about 108 million m³ more water. In the 4 seasons with less than 500 mm of rain, the reserves rose by 27 million m³ at most.</p>
<p>The three wet seasons from 2022–23 to 2024–25 had 668 mm, 580 mm and 658 mm of rain, against 721 mm in an average season. Then 2025–26 had 941 mm, the most of the 41 seasons, and the reserves rose by 410 million m³.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16"><pre><code class="language-r">line_x&lt;-c(max(min(known$rain),-coef(fit)[[1]]/slope),max(known$rain))
groups&lt;-list(list(rows=!known$year%in%c(2023:2025,latest$year),name="Other wet seasons",
                  colour=gray),
             list(rows=known$year%in%2023:2025,name="2022–23 to 2024–25",colour=blue),
             list(rows=known$year==latest$year,name=latest$name,colour=greek_red))
p&lt;-plot_ly() %&gt;%
  add_trace(x=line_x,y=predict(fit,newdata=data.frame(rain=line_x)),type="scatter",mode="lines",
            name="The straight line that fits best",hoverinfo="skip",
            line=list(color=dark_gray,width=1.5,dash="dash"))
for(g in groups) {
  p&lt;-p %&gt;%
    add_trace(data=known[g$rows,],x=~rain,y=~rise,text=~name,type="scatter",mode="markers",
              name=g$name,marker=list(color=g$colour,size=10,line=list(color="white",width=1)),
              hovertemplate=paste("%{text}: %{x:.0f} mm of rain,",
                                  "up by %{y:,.0f} million m³&lt;extra&gt;&lt;/extra&gt;"))
}
# the names of the seasons in color and of the largest rise, next to their points; two names
# that would touch move apart
labelled&lt;-known[known$year%in%c(2023:2025,latest$year,biggest$year),]
labelled&lt;-labelled[order(labelled$rise),]
shift&lt;-rep(0,nrow(labelled))
for(i in seq_len(nrow(labelled))[-1])
  if(abs(labelled$rain[i]-labelled$rain[i-1])&lt;40&amp;labelled$rise[i]-labelled$rise[i-1]&lt;30)
    shift[c(i-1,i)]&lt;-shift[c(i-1,i)]+c(-7,7)
labels&lt;-list()
for(i in seq_len(nrow(labelled)))
  labels[[i]]&lt;-list(x=labelled$rain[i],y=labelled$rise[i],text=labelled$name[i],showarrow=FALSE,
                    xanchor="left",xshift=8,yshift=shift[i],font=list(size=11,color=dark_gray))
p %&gt;%
  chart("Rain from October to April and the rise of the reserves",
        paste("EYDAP, through iMEdD Lab; ERA5 through Open-Meteo, the mean of six points over",
              "the mountains."),
        "Rise of the reserves, million m³",
        x_axis=list(title="Rain over the Evinos and the Mornos, October to April, mm"),
        legend=legend_top,margin=list(t=100,b=110),note_y=-0.2,annotations=labels)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_ATHENS_WATER.html">Interactive chart: Rain from October to April and the rise of the reserves</a></p>
</div>
</div>
<p>But in each of the last 4 seasons the reserves rose less than the line predicts for their rain, by 51 to 119 million m³. So did the first four seasons of the record, 1985–86 to 1988–89, as the drought of the early 1990s began. One possible reason is that after dry years the ground soaks up more of the rain before it reaches the rivers; another, that warmer winters let more of it evaporate. The data cannot tell which.</p>
<hr>
</section>
<section id="so-what-does-it-mean" class="level2">
<h2 class="anchored" data-anchor-id="so-what-does-it-mean">So, what does it mean?</h2>
<p><strong>Athens has as much water as its winters bring.</strong></p>
<ol type="1">
<li><strong>Low, but not the lowest</strong>: 363 million m³ in November 2025, the least since 2001; the record low was 105, in November 1993.</li>
<li><strong>A wet winter helped, but not enough</strong>: 2025–26 brought 410 million m³, and on 27 November 2026 the reserves were 58% more than a year earlier, but 36% less than the average of that day since 2002.</li>
<li><strong>The dry seasons take about the same every year</strong>: 271 million m³ on average.</li>
<li><strong>The wet seasons decide</strong>: the more rain from October to April, the more water; after less than 500 mm, little or none.</li>
</ol>
<p><strong>What this does not show.</strong> The reserves are not all the water of Athens: EYDAP also has more than a hundred boreholes, which can safely give 70 to 125 million m³ of groundwater a year (EYDAP), and those are not in the data. The fall of a dry season mixes what the city takes with what evaporates and what still flows in; the data cannot tell them apart. The rain is ERA5’s reconstruction at six points 25 km apart, not the measurements of rain gauges in the mountains. And the page does not forecast: how much water Athens has next year depends on a winter that has not come yet.</p>
<p>For the sea around Greece, see <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_AEGEAN_WARMING.html">Is the Aegean Turning Tropical?</a>, and for the heat of the summers, <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_ATHENS_HEAT.html">Athens Is Getting Hotter</a>.</p>
<hr>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<ul>
<li>EYDAP (Athens Water Supply and Sewerage Company), <a href="https://www.eydap.gr/en/TheCompany/Water/WaterSources/">Water supply resources</a>: the reservoirs, the Evinos–Mornos tunnel and the boreholes.</li>
<li>Marinou, C. (17 July 2025), <a href="https://lab.imedd.org/en/water-reserves-in-attica-from-1985-to-the-present-day/">Water reserves in Attica from 1985 to the present day</a>, iMEdD Lab; the data: <a href="https://github.com/iMEdD-Lab/eydap_water_reserves">iMEdD-Lab/eydap_water_reserves</a> on GitHub, accessed 29 November 2026.</li>
<li>Methodios, P. (19 June 2026), <a href="https://lab.imedd.org/en/the-water-reserves-of-attica-in-live-charts-that-update-daily/">The water reserves of Attica in live charts that update daily</a>, iMEdD Lab.</li>
<li>Hersbach, H. and others (2020), <a href="https://doi.org/10.1002/qj.3803">The ERA5 global reanalysis</a>, <em>Quarterly Journal of the Royal Meteorological Society</em> 146, 1999–2049; through the <a href="https://open-meteo.com/en/docs/historical-weather-api">historical weather API of Open-Meteo</a> (<a href="https://doi.org/10.5281/zenodo.7970649">Zippenfenig 2023</a>).</li>
<li>Tratsa, M. (8 December 2025), <a href="https://www.tovima.com/stories/athens-enters-drought-emergency-as-water-reserves-collapse/">Athens Enters Drought Emergency as Water Reserves Collapse</a>, <em>To Vima</em>.</li>
</ul>
<hr>
<p><em>Rendered with R 4.6.2 · plotly</em></p>
<!-- -->
</section>
<p>This post first appeared on <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_ATHENS_WATER.html">Illustrations in R</a>, with its interactive charts and the full R code.</p>]]></content:encoded>
    </item>
    <item>
      <title>When Do Young Greeks Leave Home? Living With Parents in Greece and Europe</title>
      <link>https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_GREEK_LEAVING_HOME.html</link>
      <guid isPermaLink="true">https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_GREEK_LEAVING_HOME.html</guid>
      <pubDate>Sun, 29 Nov 2026 11:15:56 +0200</pubDate>
      <category>R</category>
      <category>Illustrations in R</category>
      <description>Eurostat’s estimates of the age at which young people leave their parents’ home, by country and sex since 2000: where Greece stands in Europe, how it changed after the debt crisis, how many Greeks in their late twenties and early thirties still live with their parents, what they do, and what their housing costs.</description>
      <content:encoded><![CDATA[<p><em>Eurostat’s estimates of the age at which young people leave their parents’ home, by country and sex since 2000: where Greece stands in Europe, how it changed after the debt crisis, how many Greeks in their late twenties and early thirties still live with their parents, what they do, and what their housing costs.</em></p>
<p><img src="https://sedzinfo.github.io/vignettes/illustration/social-card.png" alt="Illustrations in R" width="1200" height="630"></p>
<section id="what-is-this" class="level2">
<h2 class="anchored" data-anchor-id="what-is-this">What is this?</h2>
<p>Young Greeks live with their parents for a long time: longer than young people almost anywhere else in Europe. This data story puts numbers on it, with five questions:</p>
<ol type="1">
<li><strong>At what age do young Europeans leave home?</strong></li>
<li><strong>Has it changed in Greece?</strong></li>
<li><strong>How many young adults live with their parents?</strong></li>
<li><strong>Do they stay because they have no job?</strong></li>
<li><strong>Is housing too expensive for them?</strong></li>
</ol>
<p>The data come from <strong>Eurostat</strong>, the statistical office of the EU, and from two of the surveys of households that it runs with the statistical offices of the countries: the <strong>Labour Force Survey</strong>, from which Eurostat estimates the average age at which young people leave the household of their parents, and the <strong>survey on income and living conditions</strong> (EU-SILC), which says who lives with their parents, what they do, and how much of a household’s income its housing takes. They are downloaded when the page is rendered, so a new render brings in the latest year.</p>
<hr>
</section>
<section id="packages" class="level2">
<h2 class="anchored" data-anchor-id="packages">Packages</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1"><pre><code class="language-r"># install.packages(c("eurostat","plotly"))
library(eurostat)
library(plotly)</code></pre></div></div>
</details>
</div>
</section>
<section id="the-data" class="level2">
<h2 class="anchored" data-anchor-id="the-data">The data</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2"><pre><code class="language-r"># a Eurostat dataset, without its missing values; the year as a number
eurostat_values&lt;-function(id,filters) {
  x&lt;-get_eurostat(id,filters=filters,time_format="num",cache=FALSE)
  result&lt;-as.data.frame(x[!is.na(x$values),])
  return(result)
}
# the names of the countries in English
country_name&lt;-c(setNames(eu_countries$name,eu_countries$code),
                setNames(efta_countries$name,efta_countries$code),
                setNames(eu_candidate_countries$name,eu_candidate_countries$code),
                UK="United Kingdom",EU27_2020="EU")
# the label of the EU's row in the chart of the countries
row_name&lt;-country_name
row_name[["EU27_2020"]]&lt;-"EU (average)"
eu&lt;-eu_countries$code
# the estimated average age at which young people leave the household of their parents, by sex,
# every year since 2000 (Labour Force Survey). The whole table, with its flags: "b" marks a break
# in a series, where the survey changed. Flags come only without filters, and the year is then
# called TIME_PERIOD
leaving&lt;-as.data.frame(get_eurostat("yth_demo_030",time_format="num",keepFlags=TRUE,cache=FALSE))
leaving&lt;-leaving[!is.na(leaving$values),]
names(leaving)[names(leaving)=="TIME_PERIOD"]&lt;-"time"
last&lt;-max(leaving$time)
breaks&lt;-sort(unique(leaving$time[leaving$geo=="EL"&amp;leaving$flags%in%"b"]))
age_of&lt;-function(geo,sex="T",year=last) {
  result&lt;-leaving$values[leaving$geo==geo&amp;leaving$sex==sex&amp;leaving$time==year]
  return(result)
}
# the countries of the last year, from the latest to leave to the earliest, with both sexes
latest&lt;-leaving[leaving$time==last&amp;leaving$geo!="EA21",]
countries&lt;-reshape(latest[,c("geo","sex","values")],idvar="geo",timevar="sex",direction="wide")
names(countries)&lt;-c("geo","women","men","all")[match(names(countries),
                                                     c("geo","values.F","values.M","values.T"))]
countries&lt;-countries[order(countries$all),]
countries$name&lt;-country_name[countries$geo]
countries$row&lt;-row_name[countries$geo]
# the place of Greece among the countries of the EU: 1 for the latest to leave; countries with
# the same age share a place
eu_ages&lt;-countries[countries$geo%in%eu,]
place&lt;-function(geo,column) {
  result&lt;-sum(eu_ages[[column]]&gt;eu_ages[[column]][eu_ages$geo==geo])+1
  return(result)
}
tied&lt;-function(geo,column) {
  result&lt;-eu_ages$name[eu_ages[[column]]==eu_ages[[column]][eu_ages$geo==geo]&amp;eu_ages$geo!=geo]
  return(result)
}
# Greece and the EU over the years; the EU's series starts in 2002
history&lt;-leaving[leaving$geo%in%c("EL","EU27_2020"),]
greek_place&lt;-sapply(sort(unique(leaving$time)),function(year) {
  x&lt;-leaving[leaving$time==year&amp;leaving$sex=="T"&amp;leaving$geo%in%eu,]
  return(sum(x$values&gt;x$values[x$geo=="EL"])+1)
})
names(greek_place)&lt;-sort(unique(leaving$time))
# the share of young adults living with their parents, by age and sex (EU-SILC)
with_parents&lt;-eurostat_values("ilc_lvps08",list(geo=c("EL","EU27_2020"),
                                                age=c("Y18-24","Y25-29","Y25-34")))
share_of&lt;-function(geo,age="Y25-34",sex="T",year=max(with_parents$time)) {
  result&lt;-with_parents$values[with_parents$geo==geo&amp;with_parents$age==age&amp;
                                with_parents$sex==sex&amp;with_parents$time==year]
  return(result)
}
silc_last&lt;-max(with_parents$time)
# what the young adults who live with their parents do: the shares of those aged 25 to 34 in
# education, in a full-time or a part-time job, unemployed, or otherwise out of work (EU-SILC)
status&lt;-eurostat_values("ilc_lvps09",list(age="Y25-34",geo=c("EL","EU27_2020")))
status_last&lt;-max(status$time)
status&lt;-status[status$time==status_last,]
doing_of&lt;-function(geo,what) {
  result&lt;-sum(status$values[status$geo==geo&amp;status$wstatus%in%what])
  return(result)
}
# the unemployment rate of the young, 15 to 24 (Labour Force Survey)
jobless&lt;-eurostat_values("une_rt_a",list(geo=c("EL","EU27_2020"),age="Y15-24",sex="T",
                                         unit="PC_ACT"))
# the share of people living in a household whose housing costs more than 40% of its income,
# by age (EU-SILC)
burden&lt;-eurostat_values("ilc_lvho07a",list(sex="T",rskpovth="TOTAL",age=c("Y15-29","TOTAL")))
burden_last&lt;-max(burden$time)
burden_of&lt;-function(geo,age="Y15-29",year=burden_last) {
  result&lt;-burden$values[burden$geo==geo&amp;burden$age==age&amp;burden$time==year]
  return(result)
}
young_burden&lt;-burden[burden$age=="Y15-29"&amp;burden$time==burden_last&amp;burden$geo%in%eu,]
young_burden&lt;-young_burden[order(-young_burden$values),]</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3"><pre><code class="language-r">greek_red&lt;-"#d62728"
blue&lt;-"#1f77b4"
gray&lt;-"#9e9e9e"
light_gray&lt;-"#ececec"
dark_gray&lt;-"#6b6b6b" # also the color of the notes and the labels
# women and men, as on the page of fertility
sex_colours&lt;-c(Women="#E74C3C",Men="#0082c8")
# the source of a chart, as a note under it, and the common layout
chart&lt;-function(p,title,source,y_title="",y_axis=list(),x_axis=list(),annotations=list(),
                margin=list(t=70,b=90),note_y=-0.16,...) {
  note&lt;-list(text=paste("Source:",source),xref="paper",yref="paper",x=0,y=note_y,xanchor="left",
             yanchor="top",align="left",showarrow=FALSE,font=list(size=11,color=dark_gray))
  result&lt;-layout(p,
                 title=list(text=title,x=0.02,xanchor="left",y=0.97,yanchor="top"),
                 yaxis=modifyList(list(title=y_title),y_axis),
                 xaxis=modifyList(list(title=""),x_axis),
                 margin=margin,
                 annotations=c(annotations,list(note)),
                 ...) %&gt;%
    config(displaylogo=FALSE)
  return(result)
}
legend_top&lt;-list(orientation="h",x=0,y=1.02,yanchor="bottom")
# short labels of numbers, places and lists
one&lt;-function(x) {
  result&lt;-format(round(x,1),nsmall=1,trim=TRUE)
  return(result)
}
percent&lt;-function(x) {
  result&lt;-paste0(round(x),"%")
  return(result)
}
ordinal&lt;-function(n) {
  suffix&lt;-ifelse(n%%100%in%11:13,"th",c("th","st","nd","rd",rep("th",6))[n%%10+1])
  result&lt;-paste0(n,suffix)
  return(result)
}
and_list&lt;-function(x) {
  result&lt;-if(length(x)&lt;2) paste(x) else paste(paste(x[-length(x)],collapse=", "),"and",
                                               x[length(x)])
  return(result)
}
# "the 2nd latest", or "joint 2nd latest" when other countries have the same age, and the names of
# those countries
place_text&lt;-function(geo,column) {
  joint&lt;-length(tied(geo,column))&gt;0
  result&lt;-paste(if(joint) "joint" else "the",ordinal(place(geo,column)),"latest")
  return(result)
}
tie_text&lt;-function(geo,column) {
  others&lt;-tied(geo,column)
  result&lt;-if(length(others)==0) "" else paste0(", with ",and_list(others),",")
  return(result)
}</code></pre></div></div>
</details>
</div>
<hr>
</section>
<section id="at-what-age-do-young-europeans-leave-home" class="level2">
<h2 class="anchored" data-anchor-id="at-what-age-do-young-europeans-leave-home">1. At what age do young Europeans leave home?</h2>
<p><strong>Late in the south and the east, early in the north.</strong> In 2025 the young people of the EU left the household of their parents at 26.3 on average, Eurostat estimates. Greece came joint 2nd latest of the 27 countries of the EU, with Slovakia, at <strong>30.9</strong>; the latest was Croatia, at 31.5, and the earliest Finland, at 21.3.</p>
<p>Women leave earlier than men in every country of the EU but Malta. In Greece the gap is 2.8 years: women leave at 29.4, men at 32.2, joint 2nd latest of the EU, with Slovakia.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4"><pre><code class="language-r">countries$label&lt;-ifelse(countries$geo=="EL",paste0("&lt;b&gt;",countries$row,"&lt;/b&gt;"),countries$row)
countries$label&lt;-factor(countries$label,levels=countries$label)
plot_ly(countries,y=~label) %&gt;%
  add_segments(x=~women,xend=~men,yend=~label,line=list(color=gray,width=2),hoverinfo="skip",
               showlegend=FALSE) %&gt;%
  add_markers(x=~women,name="Women",marker=list(color=sex_colours[["Women"]],size=9),
              hovertemplate="%{y}, women: %{x:.1f}&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  add_markers(x=~men,name="Men",marker=list(color=sex_colours[["Men"]],size=9),
              hovertemplate="%{y}, men: %{x:.1f}&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  chart(paste0("The age of leaving home, ",last),
        "Eurostat, yth_demo_030 (Labour Force Survey).",
        y_axis=list(title="",tickfont=list(size=11)),
        shapes=list(list(type="rect",xref="paper",x0=0,x1=1,yref="y",
                         y0=match("EL",countries$geo)-1.5,y1=match("EL",countries$geo)-0.5,
                         fillcolor=light_gray,line=list(width=0),layer="below")),
        legend=legend_top,margin=list(t=100,b=90,l=150),note_y=-0.08)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_GREEK_LEAVING_HOME.html">Interactive chart: The age of leaving home, 2025</a></p>
</div>
</div>
<hr>
</section>
<section id="has-it-changed-in-greece" class="level2">
<h2 class="anchored" data-anchor-id="has-it-changed-in-greece">2. Has it changed in Greece?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5"><pre><code class="language-r">first&lt;-min(history$time[history$geo=="EL"])
eu_first&lt;-min(history$time[history$geo=="EU27_2020"])
before_crisis&lt;-mean(sapply(2005:2009,function(year) age_of("EL",year=year)))
after_break&lt;-min(breaks[breaks&gt;=2015])
# the break of that year is in the series of every country
everywhere&lt;-all(unique(leaving$geo[leaving$time==after_break])%in%
                  leaving$geo[leaving$time==after_break&amp;leaving$flags%in%"b"])
jump&lt;-age_of("EL",year=after_break)-age_of("EL",year=after_break-1)
eu_jump&lt;-age_of("EU27_2020",year=after_break)-age_of("EU27_2020",year=after_break-1)</code></pre></div></div>
</details>
</div>
<p><strong>Yes: Greeks leave home later since the debt crisis, while the EU’s average has hardly moved.</strong> In 2005–2009 young Greeks left home at 28.4 on average, and in 2009 Greece was only the 11th latest of the EU; in 2025 they left at 30.9. The EU’s average went from 26.5 in 2002 to 26.3 in 2025.</p>
<p>The age rose in two steps: during the crisis, to 29.4 in 2015, and in 2021, by 1.1 years in one year. In 2021 the Labour Force Survey changed its rules in every country (Eurostat marks a break in all its series that year), so part of that step may come from the survey rather than from the young; but the EU’s average moved by only 0.2 years then, and the Greek age has stayed high since.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6"><pre><code class="language-r">lines&lt;-list(list(geo="EL",sex="F",name="Greece, women",dash="solid"),
            list(geo="EL",sex="M",name="Greece, men",dash="solid"),
            list(geo="EU27_2020",sex="F",name="EU, women",dash="dot"),
            list(geo="EU27_2020",sex="M",name="EU, men",dash="dot"))
p&lt;-plot_ly()
for(l in lines) {
  x&lt;-history[history$geo==l$geo&amp;history$sex==l$sex,]
  x&lt;-x[order(x$time),]
  colour&lt;-sex_colours[[if(l$sex=="F") "Women" else "Men"]]
  p&lt;-p %&gt;%
    add_trace(x=x$time,y=x$values,type="scatter",mode="lines+markers",name=l$name,
              line=list(color=colour,width=2.5,dash=l$dash),marker=list(color=colour,size=5),
              hovertemplate=paste0(l$name,", %{x}: %{y:.1f}&lt;extra&gt;&lt;/extra&gt;"))
}
p %&gt;%
  chart("The age of leaving home, Greece and the EU",
        "Eurostat, yth_demo_030. The dotted vertical line: the survey changed its rules.",
        "years of age",legend=legend_top,margin=list(t=110,b=90),
        shapes=list(list(type="line",x0=after_break-0.5,x1=after_break-0.5,yref="paper",y0=0,
                         y1=1,line=list(color=dark_gray,width=1,dash="dot"))))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_GREEK_LEAVING_HOME.html">Interactive chart: The age of leaving home, Greece and the EU</a></p>
</div>
</div>
<hr>
</section>
<section id="how-many-young-adults-live-with-their-parents" class="level2">
<h2 class="anchored" data-anchor-id="how-many-young-adults-live-with-their-parents">3. How many young adults live with their parents?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7"><pre><code class="language-r">peak&lt;-with_parents[with_parents$geo=="EL"&amp;with_parents$age=="Y25-34"&amp;with_parents$sex=="T",]
peak&lt;-peak[which.max(peak$values),]
silc_first&lt;-min(with_parents$time[with_parents$geo=="EL"])</code></pre></div></div>
</details>
</div>
<p><strong>More than half of Greeks aged 25 to 34.</strong> In 2025, 56% of them lived with their parents, against 30% in the EU: 49% of the women and 63% of the men. In 2003 the share was 43%; it rose through the crisis to 61% in 2021.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8"><pre><code class="language-r">p&lt;-plot_ly()
for(geo in c("EL","EU27_2020")) {
  x&lt;-with_parents[with_parents$geo==geo&amp;with_parents$age=="Y25-34"&amp;with_parents$sex=="T",]
  x&lt;-x[order(x$time),]
  colour&lt;-if(geo=="EL") greek_red else blue
  p&lt;-p %&gt;%
    add_trace(x=x$time,y=x$values,type="scatter",mode="lines+markers",name=country_name[[geo]],
              line=list(color=colour,width=2.5),marker=list(color=colour,size=5),
              hovertemplate=paste0(country_name[[geo]],", %{x}: %{y:.1f}%&lt;extra&gt;&lt;/extra&gt;"))
}
p %&gt;%
  chart("Aged 25 to 34 and living with their parents, %",
        "Eurostat, ilc_lvps08 (EU-SILC). The EU's series starts in 2010.","%",
        y_axis=list(rangemode="tozero"),legend=legend_top,margin=list(t=100,b=90))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_GREEK_LEAVING_HOME.html">Interactive chart: Aged 25 to 34 and living with their parents, %</a></p>
</div>
</div>
<hr>
</section>
<section id="do-they-stay-because-they-have-no-job" class="level2">
<h2 class="anchored" data-anchor-id="do-they-stay-because-they-have-no-job">4. Do they stay because they have no job?</h2>
<p><strong>Not most of them: most of them work.</strong> Of the Greeks aged 25 to 34 who lived with their parents in 2025, 65% had a full-time job and 6% a part-time one; 15% were unemployed, against 11% in the EU.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9"><pre><code class="language-r">activities&lt;-c(EMP_FT="Full-time job",EMP_PT="Part-time job",UNE="Unemployed",EDUC="In education",
              INAC_OTH="Other, out of work")
p&lt;-plot_ly()
for(geo in c("EU27_2020","EL")) {
  x&lt;-status[status$geo==geo,]
  x&lt;-x[match(names(activities),x$wstatus),]
  p&lt;-p %&gt;%
    add_trace(y=factor(activities,levels=rev(activities)),x=x$values,type="bar",
              orientation="h",name=country_name[[geo]],
              marker=list(color=if(geo=="EL") greek_red else blue),
              hovertemplate=paste0(country_name[[geo]],", %{y}: %{x:.1f}%&lt;extra&gt;&lt;/extra&gt;"))
}
p %&gt;%
  chart(paste0("What they do, ",status_last,", %"),
        "Eurostat, ilc_lvps09 (EU-SILC): those aged 25 to 34 who live with their parents.",
        x_axis=list(ticksuffix="%"),barmode="group",
        legend=c(legend_top,list(traceorder="reversed")),margin=list(t=100,b=80,l=130))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_GREEK_LEAVING_HOME.html">Interactive chart: What they do, 2025, %</a></p>
</div>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10"><pre><code class="language-r">greek_jobless&lt;-jobless[jobless$geo=="EL",]
worst&lt;-greek_jobless[which.max(greek_jobless$values),]
jobless_last&lt;-max(greek_jobless$time)</code></pre></div></div>
</details>
</div>
<p>Jobs came back, too. In 2013, at the worst of the crisis, 59% of the young Greeks aged 15 to 24 who worked or looked for work had no job; in 2025, 19%. Yet the age of leaving home did not fall.</p>
<hr>
</section>
<section id="is-housing-too-expensive-for-them" class="level2">
<h2 class="anchored" data-anchor-id="is-housing-too-expensive-for-them">5. Is housing too expensive for them?</h2>
<p><strong>For many it is.</strong> A household is <em>overburdened</em> by its housing when the rent or the mortgage interest, the bills and the upkeep take more than 40% of its income. In 2025, 26% of young Greeks aged 15 to 29 lived in such a household, the highest share in the EU, against 9% in the EU as a whole.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11"><pre><code class="language-r">p&lt;-plot_ly()
for(geo in c("EL","EU27_2020")) {
  x&lt;-burden[burden$geo==geo&amp;burden$age=="Y15-29",]
  x&lt;-x[order(x$time),]
  colour&lt;-if(geo=="EL") greek_red else blue
  p&lt;-p %&gt;%
    add_trace(x=x$time,y=x$values,type="scatter",mode="lines+markers",name=country_name[[geo]],
              line=list(color=colour,width=2.5),marker=list(color=colour,size=5),
              hovertemplate=paste0(country_name[[geo]],", %{x}: %{y:.1f}%&lt;extra&gt;&lt;/extra&gt;"))
}
p %&gt;%
  chart("Overburdened by housing costs, aged 15 to 29, %",
        "Eurostat, ilc_lvho07a (EU-SILC): housing costs above 40% of the household's income.",
        "%",y_axis=list(rangemode="tozero"),legend=legend_top,margin=list(t=100,b=90))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_GREEK_LEAVING_HOME.html">Interactive chart: Overburdened by housing costs, aged 15 to 29, %</a></p>
</div>
</div>
<p>The share has fallen since the worst years of the crisis, but it is still far above the EU’s; and since 2015 house prices in Greece have grown much faster than incomes (see the <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_GREEK_HOUSING.html">Greek Housing Race</a>).</p>
<hr>
</section>
<section id="so-what-does-it-mean" class="level2">
<h2 class="anchored" data-anchor-id="so-what-does-it-mean">So, what does it mean?</h2>
<p><strong>Young Greeks leave home late, and later than before the crisis.</strong></p>
<ol type="1">
<li><strong>Among the latest in Europe</strong>: at 30.9 on average in 2025, against 26.3 in the EU; men at 32.2, women at 29.4.</li>
<li><strong>Later than before the crisis</strong>: from 28.4 in 2005–2009.</li>
<li><strong>More than half of those aged 25 to 34 live with their parents</strong>: 56%, against 30% in the EU.</li>
<li><strong>Most of them work</strong>: 72% have a job.</li>
<li><strong>Housing weighs heavily</strong>: 26% of young Greeks live in a household overburdened by its housing costs, against 9% in the EU.</li>
</ol>
<p><strong>What this does not show.</strong> The surveys count households, not reasons: they cannot say whether young people stay because they cannot afford to leave, or because they choose to. The average age is Eurostat’s estimate, not a count, and the Greek series has breaks where the survey changed, in 2004, 2009 and 2021.</p>
<hr>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<ul>
<li>Eurostat, <a href="https://ec.europa.eu/eurostat/databrowser/view/yth_demo_030/default/table?lang=en">Estimated average age of young people leaving the parental household by sex</a> (yth_demo_030), from the EU Labour Force Survey.</li>
<li>Eurostat, <a href="https://ec.europa.eu/eurostat/databrowser/view/ilc_lvps08/default/table?lang=en">Share of young adults aged 18-34 living with their parents by age and sex</a> (ilc_lvps08), and <a href="https://ec.europa.eu/eurostat/databrowser/view/ilc_lvps09/default/table?lang=en">by self-defined current economic status</a> (ilc_lvps09), from EU-SILC.</li>
<li>Eurostat, <a href="https://ec.europa.eu/eurostat/databrowser/view/ilc_lvho07a/default/table?lang=en">Housing cost overburden rate by age, sex and poverty status</a> (ilc_lvho07a), from EU-SILC.</li>
<li>Eurostat, <a href="https://ec.europa.eu/eurostat/databrowser/view/une_rt_a/default/table?lang=en">Unemployment by sex and age, annual data</a> (une_rt_a).</li>
<li>Eurostat (30 September 2024), <a href="https://ec.europa.eu/eurostat/web/products-eurostat-news/w/ddn-20240930-2">Age of leaving the parental home steady in 2023</a>.</li>
</ul>
<hr>
<p><em>Rendered with R 4.6.2 · eurostat · plotly</em></p>
<!-- -->
</section>
<p>This post first appeared on <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_GREEK_LEAVING_HOME.html">Illustrations in R</a>, with its interactive charts and the full R code.</p>]]></content:encoded>
    </item>
    <item>
      <title>Is the Aegean Turning Tropical? The Temperature of the Sea Since 1982</title>
      <link>https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_AEGEAN_WARMING.html</link>
      <guid isPermaLink="true">https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_AEGEAN_WARMING.html</guid>
      <pubDate>Sun, 29 Nov 2026 10:53:46 +0200</pubDate>
      <category>R</category>
      <category>Illustrations in R</category>
      <description>NOAA’s daily temperature of the sea surface since 1982, over the whole Aegean: how much warmer the sea has become, in which months and where, how warm its summers get, and its marine heatwaves.</description>
      <content:encoded><![CDATA[<p><em>NOAA’s daily temperature of the sea surface since 1982, over the whole Aegean: how much warmer the sea has become, in which months and where, how warm its summers get, and its marine heatwaves.</em></p>
<p><img src="https://sedzinfo.github.io/vignettes/illustration/social-card.png" alt="Illustrations in R" width="1200" height="630"></p>
<section id="what-is-this" class="level2">
<h2 class="anchored" data-anchor-id="what-is-this">What is this?</h2>
<p>Swimmers in Greece say that the sea is warmer than it used to be, and that it stays warm longer into the autumn. This data story checks that against the measurements of satellites, ships and buoys, every day since 1982 and over the whole Aegean, with five questions:</p>
<ol type="1">
<li><strong>How is the temperature of the sea measured?</strong></li>
<li><strong>Is the Aegean warmer than it used to be?</strong></li>
<li><strong>In which months, and where?</strong></li>
<li><strong>Is the Aegean turning tropical?</strong></li>
<li><strong>Are marine heatwaves more common?</strong></li>
</ol>
<p>The data come from NOAA, the US agency for weather, oceans and climate: its <strong>Daily Optimum Interpolation Sea Surface Temperature</strong> (OISST), version 2.1, the temperature of the sea surface every day since September 1981, on a grid that covers all the oceans (<a href="https://doi.org/10.1175/JCLI-D-20-0166.1">Huang et al.&nbsp;2021</a>). The page downloads the part of the grid around the Aegean when it is rendered. The outline of the Aegean is the one the International Hydrographic Organization (IHO) draws, from <a href="https://www.marineregions.org/">Marine Regions</a>.</p>
<p><strong>The words of this page:</strong></p>
<ul>
<li>the <strong>temperature of the sea</strong> is that of the water at the surface;</li>
<li>the <strong>normal</strong> temperature of a day is the average of the same time of the year in 1982–2011, the first thirty years of the record;</li>
<li>a <strong>marine heatwave</strong> is at least five days in a row on which the sea is warmer than on nine in ten of the same days of 1982–2011, as <a href="https://doi.org/10.1016/j.pocean.2015.12.014">Hobday and others (2016)</a> define it.</li>
</ul>
<hr>
</section>
<section id="packages" class="level2">
<h2 class="anchored" data-anchor-id="packages">Packages</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1"><pre><code class="language-r"># install.packages(c("plotly","ncdf4","sf"))
library(plotly)
library(sf)</code></pre></div></div>
</details>
</div>
</section>
<section id="the-data" class="level2">
<h2 class="anchored" data-anchor-id="the-data">The data</h2>
<section id="the-temperature-of-the-sea" class="level3">
<h3 class="anchored" data-anchor-id="the-temperature-of-the-sea">The temperature of the sea</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2"><pre><code class="language-r"># the downloads are kept here between renders: a finished year of OISST never changes
kept&lt;-tools::R_user_dir("illustration",which="cache")
dir.create(kept,recursive=TRUE,showWarnings=FALSE)
# a file from the web, tried again a few times: the servers sometimes refuse a connection or take
# too long to answer
download&lt;-function(url,file,tries=4) {
  for(k in seq_len(tries)) {
    done&lt;-tryCatch(download.file(url,file,mode="wb",quiet=TRUE)==0,error=function(e) FALSE)
    if(done)
      return(invisible(file))
    Sys.sleep(10)
  }
  stop("Could not download ",url)
}
# the centers of the cells of the grid around the Aegean, every quarter of a degree
lons&lt;-seq(22.375,28.625,by=0.25)
lats&lt;-seq(34.875,41.375,by=0.25)
# the last day of the final record on NOAA's ERDDAP server at CoastWatch: the days of the last two
# weeks are still preliminary, and are left out
erddap&lt;-"https://coastwatch.pfeg.noaa.gov/erddap/griddap/ncdcOisst21Agg_LonPM180"
last_file&lt;-tempfile(fileext=".csv")
download(paste0(erddap,".csv?time%5B(last)%5D"),last_file)
last_day&lt;-as.Date(substr(read.csv(last_file,skip=2,header=FALSE)[[1]],1,10))
# one year of OISST from ERDDAP: the temperature of the surface (°C, NA on land) as an array of
# longitude, latitude and day; the days the server lacks stay NA
erddap_year&lt;-function(year,days) {
  query&lt;-paste0("sst%5B(",min(days),"):1:(",max(days),")%5D%5B(0.0)%5D%5B(",min(lats),"):1:(",
                max(lats),")%5D%5B(",min(lons),"):1:(",max(lons),")%5D")
  file&lt;-tempfile(fileext=".nc")
  download(paste0(erddap,".nc?",query),file)
  nc&lt;-ncdf4::nc_open(file)
  sst&lt;-ncdf4::ncvar_get(nc,"sst",collapse_degen=FALSE)
  served&lt;-as.Date(as.POSIXct(ncdf4::ncvar_get(nc,"time"),origin="1970-01-01",tz="UTC"))
  ncdf4::nc_close(nc)
  unlink(file)
  # the days asked for, each in its place: when the first or the last day is missing, the server
  # sends the nearest day it has instead, which can belong to the next or the last year
  found&lt;-match(served,days)
  result&lt;-array(NA_real_,c(length(lons),length(lats),length(days)))
  result[,,found[!is.na(found)]]&lt;-sst[,,1,!is.na(found)]
  return(result)
}
# some days of a year from the copy of OISST at NOAA's Physical Sciences Laboratory (PSL), which has
# every day: it is the same record, but slower to cut, so it only fills the days that ERDDAP lacks.
# first and last count the days of the year from 0
psl_days&lt;-function(year,first,last) {
  url&lt;-paste0("https://psl.noaa.gov/thredds/dodsC/Datasets/noaa.oisst.v2.highres/sst.day.mean.",
              year,".nc.ascii?sst%5B",first,":",last,"%5D%5B",(min(lats)+89.875)/0.25,":",
              (max(lats)+89.875)/0.25,"%5D%5B",(min(lons)-0.125)/0.25,":",
              (max(lons)-0.125)/0.25,"%5D")
  file&lt;-tempfile(fileext=".txt")
  download(url,file)
  rows&lt;-grep("^\\[",readLines(file),value=TRUE)
  unlink(file)
  # each row is "[day][latitude], value, value, ...", with a value for each longitude; land is a
  # very large negative number
  index&lt;-matrix(as.integer(unlist(regmatches(rows,gregexpr("[0-9]+(?=\\])",rows,perl=TRUE)))),
                ncol=2,byrow=TRUE)
  values&lt;-matrix(as.numeric(unlist(strsplit(sub("^[^,]*, ","",rows),", "))),ncol=length(lons),
                 byrow=TRUE)
  values[values&lt; -50]&lt;-NA
  result&lt;-array(NA_real_,c(length(lons),length(lats),last-first+1))
  for(k in seq_along(rows))
    result[,index[k,2]+1,index[k,1]+1]&lt;-values[k,]
  return(result)
}
# one year of OISST, kept in the cache folder; the year of the last day is downloaded again when its
# copy is more than a day old
oisst_year&lt;-function(year) {
  file&lt;-file.path(kept,paste0("oisst_aegean_",year,".rds"))
  current&lt;-year==as.integer(format(last_day,"%Y"))
  fresh&lt;-file.exists(file)&amp;&amp;(!current||difftime(Sys.time(),file.mtime(file),units="hours")&lt;24)
  if(fresh)
    return(readRDS(file))
  days&lt;-seq(as.Date(paste0(year,"-01-01")),min(last_day,as.Date(paste0(year,"-12-31"))),by="day")
  sst&lt;-erddap_year(year,days)
  # the days that ERDDAP lacks (most of them in 1992-1998), in runs of consecutive days
  lacking&lt;-which(apply(sst,3,function(x) all(is.na(x))))
  runs&lt;-split(lacking,cumsum(diff(c(-1,lacking))!=1))
  for(run in runs)
    sst[,,run]&lt;-psl_days(year,min(run)-1,max(run)-1)
  result&lt;-list(days=days,sst=sst,from_psl=length(lacking))
  saveRDS(result,file)
  return(result)
}
years&lt;-1982:as.integer(format(last_day,"%Y"))
parts&lt;-lapply(years,oisst_year)
dates&lt;-do.call(c,lapply(parts,function(p) p$days))
from_psl&lt;-sapply(parts,function(p) p$from_psl)
# a row for each cell of the grid (the longitude changing fastest), a column for each day
grid&lt;-do.call(cbind,lapply(parts,function(p) matrix(p$sst,ncol=length(p$days))))
rm(parts)
year&lt;-as.integer(format(dates,"%Y"))
month&lt;-as.integer(format(dates,"%m"))
# the last whole year of the record, and the years of comparison: the first and the last ten
last_year&lt;-max(year[month==12&amp;as.integer(format(dates,"%d"))==31])
first_ten&lt;-1982:1991
last_ten&lt;-(last_year-9):last_year</code></pre></div></div>
</details>
</div>
</section>
<section id="the-aegean" class="level3">
<h3 class="anchored" data-anchor-id="the-aegean">The Aegean</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3"><pre><code class="language-r"># the seas of the IHO around the Aegean, from Marine Regions; their outlines do not change, so they
# are kept
seas_file&lt;-file.path(kept,"iho_seas_aegean.geojson")
if(!file.exists(seas_file))
  download(paste0("https://geo.vliz.be/geoserver/MarineRegions/wfs?service=WFS&amp;version=1.0.0&amp;",
                  "request=GetFeature&amp;typeName=MarineRegions:iho&amp;outputFormat=application/json&amp;",
                  "propertyName=name,the_geom&amp;CQL_FILTER=name%20IN%20(%27Aegean%20Sea%27,",
                  "%27Ionian%20Sea%27,%27Sea%20of%20Marmara%27,",
                  "%27Mediterranean%20Sea%20-%20Eastern%20Basin%27)"),seas_file)
seas&lt;-st_read(seas_file,quiet=TRUE)
# the cells with a temperature (the others are land), each in the sea its center lies in; a cell
# by the coast whose center lies on land goes to the sea nearest to it
cells&lt;-expand.grid(lon=lons,lat=lats)
wet&lt;-!is.na(grid[,1])
centres&lt;-st_as_sf(cells[wet,],coords=c("lon","lat"),crs=4326)
cells$sea&lt;-NA
cells$sea[wet]&lt;-seas$name[st_nearest_feature(centres,seas)]
cells$inside&lt;-FALSE
cells$inside[wet]&lt;-lengths(st_intersects(centres,seas[seas$name=="Aegean Sea",]))&gt;0
aegean&lt;-which(cells$sea=="Aegean Sea")
# the temperature of the Aegean's cells. A cell counts in the mean of the whole sea by its area,
# which shrinks towards the north with the cosine of the latitude
sea&lt;-grid[aegean,]
rm(grid)
weights&lt;-cos(cells$lat[aegean]*pi/180)
aegean_mean&lt;-colSums(sea*weights)/sum(weights)
# the area of the cells, km²: a quarter of a degree of latitude is 27.8 km
area&lt;-sum(weights)*27.8^2
# the land around the Aegean, for the maps: the countries of GISCO (NUTS 2024, 1:3 million), cut
# to the maps' frame
gisco&lt;-"https://gisco-services.ec.europa.eu/distribution/v2/nuts/"
land&lt;-st_read(paste0(gisco,"geojson/NUTS_RG_03M_2024_4326_LEVL_0.geojson"),quiet=TRUE)
land&lt;-land[land$CNTR_CODE%in%c("EL","TR","BG","MK","AL"),]
frame&lt;-c(xmin=22,ymin=34.5,xmax=29,ymax=41.8)
sf_use_s2(FALSE)
land&lt;-st_crop(st_make_valid(land),frame)
sf_use_s2(TRUE)</code></pre></div></div>
</details>
</div>
</section>
<section id="normal-days-and-marine-heatwaves" class="level3">
<h3 class="anchored" data-anchor-id="normal-days-and-marine-heatwaves">Normal days and marine heatwaves</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4"><pre><code class="language-r"># the day of a year of 366 days, in which 1 March is always day 61: a day of the year then falls on
# the same date in every year, and 29 February has a day of its own
day_366&lt;-function(date) {
  year&lt;-as.integer(format(date,"%Y"))
  day&lt;-as.integer(format(date,"%j"))
  leap&lt;-(year%%4==0&amp;year%%100!=0)|year%%400==0
  result&lt;-ifelse(!leap&amp;day&gt;=60,day+1L,day)
  return(result)
}
# the temperatures of the base years as an array of cells, days of the year (1-366) and years; 29
# February of the other years is the mean of 28 February and 1 March
base_table&lt;-function(temperature,dates,base) {
  result&lt;-array(NA_real_,c(nrow(temperature),366,length(base)))
  for(k in seq_along(base)) {
    in_year&lt;-format(dates,"%Y")==base[k]
    result[,day_366(dates[in_year]),k]&lt;-temperature[,in_year]
    if(all(is.na(result[,60,k])))
      result[,60,k]&lt;-(result[,59,k]+result[,61,k])/2
  }
  return(result)
}
# the mean of the 31 days around each day of the year, across the turn of the year
smooth_31&lt;-function(x) {
  result&lt;-x
  for(d in 1:366)
    result[,d]&lt;-rowMeans(x[,(d+(-15:15)-1)%%366+1,drop=FALSE])
  return(result)
}
# the climate of every cell (row) on every day of the year, as Hobday and others (2016) define it:
# the mean and the 90th percentile of the base years' temperatures within five days of that day,
# both smoothed by the mean of the 31 days around it
climate_of&lt;-function(temperature,dates,base) {
  table&lt;-base_table(temperature,dates,base)
  normal&lt;-matrix(NA_real_,nrow(temperature),366)
  threshold&lt;-normal
  for(d in 1:366) {
    pooled&lt;-matrix(table[,(d+(-5:5)-1)%%366+1,],nrow(temperature))
    normal[,d]&lt;-rowMeans(pooled)
    threshold[,d]&lt;-apply(pooled,1,quantile,probs=0.9,names=FALSE)
  }
  result&lt;-list(normal=smooth_31(normal),threshold=smooth_31(threshold))
  return(result)
}
# whether each day of a series belongs to a marine heatwave (Hobday et al. 2016): at least five days
# in a row above the threshold; two heatwaves with no more than two days between them are one
heatwave_days&lt;-function(above) {
  runs&lt;-rle(above)
  runs$values[runs$values&amp;runs$lengths&lt;5]&lt;-FALSE
  runs&lt;-rle(inverse.rle(runs))
  before&lt;-c(FALSE,head(runs$values,-1))
  after&lt;-c(tail(runs$values,-1),FALSE)
  runs$values[!runs$values&amp;runs$lengths&lt;=2&amp;before&amp;after]&lt;-TRUE
  result&lt;-inverse.rle(runs)
  return(result)
}
base&lt;-1982:2011
day&lt;-day_366(dates)
# the normal and the threshold of every cell on every day, and its heatwaves
climate&lt;-climate_of(sea,dates,base)
normal&lt;-climate$normal[,day]
threshold&lt;-climate$threshold[,day]
heatwave&lt;-t(apply(sea&gt;threshold,1,heatwave_days))
# how strong each day of a heatwave was (Hobday et al. 2018): how many times the distance from the
# normal to the threshold the sea was above the normal. 1 moderate (up to twice), 2 strong (twice
# to three times), 3 severe (three to four times), 4 extreme (four times or more); 0 no heatwave
times&lt;-floor((sea-normal)/(threshold-normal))
category&lt;-ifelse(heatwave,pmin(pmax(times,1),4),0)
rm(normal,threshold,times)
# the same for the mean of the whole Aegean
mean_climate&lt;-climate_of(matrix(aegean_mean,1),dates,base)
mean_normal&lt;-mean_climate$normal[1,day]
mean_threshold&lt;-mean_climate$threshold[1,day]
anomaly&lt;-aegean_mean-mean_normal
mean_heatwave&lt;-heatwave_days(aegean_mean&gt;mean_threshold)</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5"><pre><code class="language-r">greek_red&lt;-"#d62728"
blue&lt;-"#1f77b4"
gray&lt;-"#9e9e9e"
dark_gray&lt;-"#6b6b6b" # also the color of the notes and the labels
land_gray&lt;-"#d9d9d9"
other_sea&lt;-"#eef2f6" # the seas around the Aegean on the maps
# the colors of the categories of marine heatwaves, as in Hobday and others (2018)
category_colours&lt;-c(Moderate="#ffc866",Strong="#ff6900",Severe="#9e0000",Extreme="#2d0000")
# blue below the normal, red above it: ColorBrewer's RdBu, from -3 °C to +3 °C
anomaly_colours&lt;-list(c(0,"#2166ac"),c(0.17,"#4393c3"),c(0.33,"#92c5de"),c(0.45,"#d1e5f0"),
                      c(0.5,"#f7f7f7"),c(0.55,"#fddbc7"),c(0.67,"#f4a582"),c(0.83,"#d6604d"),
                      c(1,"#b2182b"))
# the source of a chart, as a note under it, and the common layout
chart&lt;-function(p,title,source,y_title="",y_axis=list(),x_axis=list(),annotations=list(),
                margin=list(t=70,b=90),note_y=-0.16,...) {
  note&lt;-list(text=paste("Source:",source),xref="paper",yref="paper",x=0,y=note_y,xanchor="left",
             yanchor="top",align="left",showarrow=FALSE,font=list(size=11,color=dark_gray))
  result&lt;-layout(p,
                 title=list(text=title,x=0.02,xanchor="left",y=0.97,yanchor="top"),
                 yaxis=modifyList(list(title=y_title),y_axis),
                 xaxis=modifyList(list(title=""),x_axis),
                 margin=margin,
                 annotations=c(annotations,list(note)),
                 ...) %&gt;%
    config(displaylogo=FALSE)
  return(result)
}
legend_top&lt;-list(orientation="h",x=0,y=1.02,yanchor="bottom")
oisst_source&lt;-"NOAA OISST v2.1"
# the outline of polygons as one path for plotly, the rings separated by NA, to a thousandth of a
# degree
outline_path&lt;-function(x) {
  xy&lt;-st_coordinates(st_cast(st_geometry(x),"MULTIPOLYGON"))
  ring&lt;-paste(xy[,"L1"],xy[,"L2"],xy[,"L3"])
  rings&lt;-split(as.data.frame(round(xy[,c("X","Y")],3)),factor(ring,levels=unique(ring)))
  result&lt;-do.call(rbind,lapply(rings,function(r) rbind(r,NA)))
  return(result)
}
land_path&lt;-outline_path(land)
# a value for every cell of the Aegean as a table for a plotly heatmap: a row for each latitude, a
# column for each longitude, and empty outside the Aegean
cell_table&lt;-function(values,empty=NA) {
  all_cells&lt;-rep(empty,nrow(cells))
  all_cells[aegean]&lt;-values
  result&lt;-t(matrix(all_cells,nrow=length(lons)))
  return(result)
}
# a map of the Aegean's cells colored by a value, with the land on top, drawn on the axes x and y
sea_map&lt;-function(p,values,hover,x="x",y="y",...) {
  result&lt;-p %&gt;%
    add_trace(x=lons,y=lats,z=cell_table(values),text=cell_table(hover,""),type="heatmap",
              xaxis=x,yaxis=y,hoverongaps=FALSE,hovertemplate="%{text}&lt;extra&gt;&lt;/extra&gt;",...) %&gt;%
    add_trace(data=land_path,x=~X,y=~Y,type="scatter",mode="lines",fill="toself",
              fillcolor=land_gray,line=list(color="white",width=0.6),hoverinfo="skip",
              showlegend=FALSE,inherit=FALSE,xaxis=x,yaxis=y)
  return(result)
}
# the axes of a map: a degree of longitude is cos(38°) times a degree of latitude in the middle of
# the Aegean. domain is the part of the chart's width that the map may take; the map keeps its
# shape and moves to the top of the space it is given
map_axes&lt;-function(domain=c(0,1),x="x",y="y") {
  result&lt;-list(x=list(range=c(22.3,28.7),domain=domain,anchor=y,constrain="domain",visible=FALSE),
               y=list(range=c(34.85,41.35),anchor=x,scaleanchor=x,scaleratio=1/cos(38*pi/180),
                      constrain="domain",constraintoward="top",visible=FALSE))
  return(result)
}
# short labels of numbers and dates
one&lt;-function(x) {
  result&lt;-format(round(x,1),nsmall=1,trim=TRUE)
  return(result)
}
two&lt;-function(x) {
  result&lt;-format(round(x,2),nsmall=2,trim=TRUE)
  return(result)
}
signed&lt;-function(x) {
  result&lt;-paste0(ifelse(round(x,1)&gt;0,"+",""),one(x))
  return(result)
}
date_text&lt;-function(d) {
  result&lt;-paste(as.integer(format(d,"%d")),month.name[as.integer(format(d,"%m"))],format(d,"%Y"))
  return(result)
}
and_list&lt;-function(x) {
  result&lt;-if(length(x)&lt;2) paste(x) else paste(paste(x[-length(x)],collapse=", "),"and",
                                               x[length(x)])
  return(result)
}
capital&lt;-function(x) {
  result&lt;-paste0(toupper(substr(x,1,1)),substring(x,2))
  return(result)
}</code></pre></div></div>
</details>
</div>
<hr>
</section>
</section>
<section id="how-is-the-temperature-of-the-sea-measured" class="level2">
<h2 class="anchored" data-anchor-id="how-is-the-temperature-of-the-sea-measured">1. How is the temperature of the sea measured?</h2>
<p><strong>Mostly from space, checked against the sea itself.</strong> Since 1981, weather satellites have measured the temperature of the sea surface from the infrared light it gives off. They see only the thinnest skin of the water, and not at all through clouds. Ships, buoys and floats measure the water itself, but only where they happen to be. Every day NOAA combines the two into one map of the world’s seas: it corrects the satellites to what the ships and buoys measure, and fills the gaps under the clouds from the days and the places around them (<a href="https://doi.org/10.1175/2007JCLI1824.1">Reynolds et al.&nbsp;2007</a>).</p>
<p>The map is a grid of cells of a quarter of a degree: about 28 km from north to south and 22 km from east to west at the latitude of the Aegean. 345 cells make up the Aegean, about 210,000 km² with the land along its coasts: the 308 whose center lies in the Aegean as the IHO draws it, from the Dardanelles to Crete and Rhodes, and 37 along its coasts whose center falls on land but which lie closest to it. A grid this coarse cannot see small bays and harbors; it describes the open sea. The mean of the whole Aegean, on which most of this page rests, counts each cell by its area.</p>
<p>The record runs from 1 January 1982 to 13 November 2026. NOAA’s ERDDAP server at CoastWatch, from which the page downloads it, lacks 1,196 of these days, 1,177 of them in 1992–1998; they come from the copy at NOAA’s Physical Sciences Laboratory, which gives the same temperatures for the days that both have.</p>
<hr>
</section>
<section id="is-the-aegean-warmer-than-it-used-to-be" class="level2">
<h2 class="anchored" data-anchor-id="is-the-aegean-warmer-than-it-used-to-be">2. Is the Aegean warmer than it used to be?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6"><pre><code class="language-r">yearly&lt;-aggregate(list(temperature=aegean_mean[year&lt;=last_year]),list(year=year[year&lt;=last_year]),
                  mean)
fit&lt;-lm(temperature~year,yearly)
per_decade&lt;-10*unname(coef(fit)[2])
first_mean&lt;-mean(yearly$temperature[yearly$year%in%first_ten])
last_mean&lt;-mean(yearly$temperature[yearly$year%in%last_ten])
ranked&lt;-yearly[order(-yearly$temperature),]</code></pre></div></div>
</details>
</div>
<p><strong>Yes: by 1.4 °C over the year as a whole.</strong> In 1982–1991 the surface of the Aegean averaged 18.7 °C; in 2016–2025, 20.1 °C. A straight line through the means of the years rises by 0.39 °C a decade, 1.7 °C from 1982 to 2025. The five warmest years were 2018, 2021, 2023, 2024 and 2025, and the warmest of all, 2024, averaged 20.6 °C.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7"><pre><code class="language-r">plot_ly(yearly,x=~year,y=~temperature,type="scatter",mode="lines+markers",name="Mean of the year",
        line=list(color=gray,width=1.5),marker=list(color=gray,size=6),
        hovertemplate="%{x}: %{y:.2f} °C&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  add_trace(x=yearly$year,y=fitted(fit),type="scatter",mode="lines",
            name=paste0("Trend: ",signed(per_decade)," °C a decade"),
            line=list(color=greek_red,width=3),hoverinfo="skip",inherit=FALSE) %&gt;%
  chart("The surface of the Aegean, mean of each year, °C",
        paste0(oisst_source,", ",min(years),"–",last_year,": the mean of the Aegean's cells, ",
               "each by its area."),
        "°C",legend=legend_top,margin=list(t=100,b=90))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_AEGEAN_WARMING.html">Interactive chart: The surface of the Aegean, mean of each year, °C</a></p>
</div>
</div>
<hr>
</section>
<section id="in-which-months-and-where" class="level2">
<h2 class="anchored" data-anchor-id="in-which-months-and-where">3. In which months, and where?</h2>
<section id="every-day-since-1982" class="level3">
<h3 class="anchored" data-anchor-id="every-day-since-1982">Every day since 1982</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8"><pre><code class="language-r">warmer_first&lt;-100*mean(anomaly[year%in%first_ten]&gt;0)
warmer_last&lt;-100*mean(anomaly[year%in%last_ten]&gt;0)
# the mean temperature of each month in the first and the last ten years
monthly&lt;-aggregate(list(temperature=aegean_mean),list(year=year,month=month),mean)
monthly&lt;-monthly[monthly$year&lt;=last_year,]
month_mean&lt;-function(months,period) {
  rows&lt;-months$year%in%period
  result&lt;-tapply(months$temperature[rows],months$month[rows],mean)
  return(result)
}
by_month&lt;-data.frame(month=month.name,first=month_mean(monthly,first_ten),
                     last=month_mean(monthly,last_ten))
by_month$change&lt;-by_month$last-by_month$first
most_months&lt;-by_month$month[order(-by_month$change)][1:2]
least_months&lt;-by_month$month[order(by_month$change)][1:2]
# the seasons by the mean change of their months; the one that warmed most, and the next one too
# when it warmed within 0.1 °C as much
seasons&lt;-list(winter=c(12,1,2),spring=3:5,summer=6:8,autumn=9:11)
season_change&lt;-sort(sapply(seasons,function(m) mean(by_month$change[m])),decreasing=TRUE)
top_seasons&lt;-names(season_change)[c(TRUE,season_change[2]&gt;season_change[1]-0.1,FALSE,FALSE)]</code></pre></div></div>
</details>
</div>
<p><strong>Every month, and the winter and the autumn most.</strong> Each row below is a year, each column a day, colored by how much warmer (red) or cooler (blue) the Aegean was than the normal of that day. In 1982–1991, 29% of the days were warmer than normal; in 2016–2025, 94%.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9"><pre><code class="language-r"># a row for each year, a column for each day of a year of 365 days: 29 February is left out, or
# the other years would show a gap there
leap_day&lt;-day==60
anomaly_table&lt;-matrix(NA_real_,length(years),365)
anomaly_table[cbind(year[!leap_day]-min(years)+1,(day-(day&gt;60))[!leap_day])]&lt;-anomaly[!leap_day]
common_year&lt;-as.Date("2023-01-01")+0:364 # the dates of the columns
month_starts&lt;-as.Date(paste0("2023-",1:12,"-01"))
plot_ly(x=common_year,y=years,z=anomaly_table,type="heatmap",zmin=-3,zmax=3,
        colorscale=anomaly_colours,hoverongaps=FALSE,
        colorbar=list(orientation="h",x=0,xanchor="left",y=-0.06,yanchor="top",len=0.6,
                      thickness=12,ticksuffix=" °C",
                      title=list(text="Against the normal of the day",side="top"))) %&gt;%
  style(hovertemplate="%{x|%e %B} %{y}: %{z:+.1f} °C&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  chart("Every day since 1982: warmer or cooler than normal",
        paste0(oisst_source,": the mean of the Aegean against the normal of the same day ",
               "in 1982–2011; 29 February left out."),
        x_axis=list(tickvals=month_starts+14,ticktext=month.abb,showgrid=FALSE),
        y_axis=list(dtick=5,showgrid=FALSE),margin=list(t=60,b=150),note_y=-0.2)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_AEGEAN_WARMING.html">Interactive chart: Every day since 1982: warmer or cooler than normal</a></p>
</div>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10"><pre><code class="language-r">knitr::kable(data.frame(by_month$month,one(by_month$first),one(by_month$last),
                        signed(by_month$change)),
             col.names=c("Month",paste0(min(first_ten),"–",max(first_ten)," (°C)"),
                         paste0(min(last_ten),"–",last_year," (°C)"),"Change (°C)"),
             align="lrrr")</code></pre></div></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: left;">Month</th>
<th style="text-align: right;">1982–1991 (°C)</th>
<th style="text-align: right;">2016–2025 (°C)</th>
<th style="text-align: right;">Change (°C)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">January</td>
<td style="text-align: right;">15.0</td>
<td style="text-align: right;">16.5</td>
<td style="text-align: right;">+1.5</td>
</tr>
<tr class="even">
<td style="text-align: left;">February</td>
<td style="text-align: right;">14.5</td>
<td style="text-align: right;">15.8</td>
<td style="text-align: right;">+1.3</td>
</tr>
<tr class="odd">
<td style="text-align: left;">March</td>
<td style="text-align: right;">14.5</td>
<td style="text-align: right;">15.8</td>
<td style="text-align: right;">+1.3</td>
</tr>
<tr class="even">
<td style="text-align: left;">April</td>
<td style="text-align: right;">15.8</td>
<td style="text-align: right;">16.7</td>
<td style="text-align: right;">+0.9</td>
</tr>
<tr class="odd">
<td style="text-align: left;">May</td>
<td style="text-align: right;">18.2</td>
<td style="text-align: right;">19.0</td>
<td style="text-align: right;">+0.8</td>
</tr>
<tr class="even">
<td style="text-align: left;">June</td>
<td style="text-align: right;">21.5</td>
<td style="text-align: right;">22.5</td>
<td style="text-align: right;">+1.1</td>
</tr>
<tr class="odd">
<td style="text-align: left;">July</td>
<td style="text-align: right;">23.3</td>
<td style="text-align: right;">24.8</td>
<td style="text-align: right;">+1.4</td>
</tr>
<tr class="even">
<td style="text-align: left;">August</td>
<td style="text-align: right;">23.8</td>
<td style="text-align: right;">25.4</td>
<td style="text-align: right;">+1.5</td>
</tr>
<tr class="odd">
<td style="text-align: left;">September</td>
<td style="text-align: right;">23.0</td>
<td style="text-align: right;">24.4</td>
<td style="text-align: right;">+1.4</td>
</tr>
<tr class="even">
<td style="text-align: left;">October</td>
<td style="text-align: right;">20.7</td>
<td style="text-align: right;">22.1</td>
<td style="text-align: right;">+1.4</td>
</tr>
<tr class="odd">
<td style="text-align: left;">November</td>
<td style="text-align: right;">18.0</td>
<td style="text-align: right;">19.8</td>
<td style="text-align: right;">+1.9</td>
</tr>
<tr class="even">
<td style="text-align: left;">December</td>
<td style="text-align: right;">16.1</td>
<td style="text-align: right;">17.9</td>
<td style="text-align: right;">+1.8</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The mean temperature of every month rose: most in November and December, by 1.9 °C, and least in May and April, by 0.8 °C. So the warm season is longer, as the next question shows.</p>
</section>
<section id="where-it-warms-fastest" class="level3">
<h3 class="anchored" data-anchor-id="where-it-warms-fastest">Where it warms fastest</h3>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11"><pre><code class="language-r"># the trend of every cell: a straight line through the means of its years, °C a decade
trend_years&lt;-min(years):last_year
cell_years&lt;-sapply(trend_years,function(y) rowMeans(sea[,year==y]))
cell_trend&lt;-10*apply(cell_years,1,function(v) cov(trend_years,v)/var(trend_years))
# where a group of cells lies, seen from the middle of the Aegean: "north-west" and so on
direction&lt;-function(rows) {
  north&lt;-mean(cells$lat[aegean][rows])-mean(cells$lat[aegean])
  east&lt;-(mean(cells$lon[aegean][rows])-mean(cells$lon[aegean]))*cos(38*pi/180)
  angle&lt;-atan2(north,east)*180/pi
  compass&lt;-c("east","north-east","north","north-west","west","south-west","south","south-east")
  result&lt;-compass[round(((angle+360)%%360)/45)%%8+1]
  return(result)
}
# the tenth of the cells that warmed fastest, and the tenth that warmed slowest
fastest&lt;-which(cell_trend&gt;=quantile(cell_trend,0.9))
slowest&lt;-which(cell_trend&lt;=quantile(cell_trend,0.1))</code></pre></div></div>
</details>
</div>
<p><strong>Everywhere, by 0.27 to 0.48 °C a decade</strong>: fastest in the north-west of the Aegean, slowest in the north. Each cell of the grid below is colored by a straight line through the means of its years.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12"><pre><code class="language-r">hover&lt;-paste0(one(cells$lat[aegean]),"°N ",one(cells$lon[aegean]),"°E: ",signed(cell_trend),
              " °C a decade")
low&lt;-floor(10*min(cell_trend))/10
high&lt;-ceiling(10*max(cell_trend))/10
plot_ly() %&gt;%
  sea_map(cell_trend,hover,zmin=low,zmax=high,colorscale="YlOrRd",reversescale=TRUE,
          colorbar=list(title=list(text="°C a&lt;br&gt;decade"),thickness=12,len=0.6)) %&gt;%
  chart(paste0("Warming of the surface, ",min(trend_years),"–",last_year),
        paste0(oisst_source,": a straight line through the means of the years of each cell; ",
               "land: GISCO © EuroGeographics."),
        x_axis=map_axes()$x,y_axis=map_axes()$y,plot_bgcolor=other_sea,
        margin=list(t=60,b=50,l=10,r=10),note_y=-0.02)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_AEGEAN_WARMING.html">Interactive chart: Warming of the surface, 1982–2025</a></p>
</div>
</div>
<hr>
</section>
</section>
<section id="is-the-aegean-turning-tropical" class="level2">
<h2 class="anchored" data-anchor-id="is-the-aegean-turning-tropical">4. Is the Aegean turning tropical?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13"><pre><code class="language-r"># the temperature that, NOAA says, hurricanes need in the top 50 meters of the sea
tropical&lt;-26.5
# the mean of each day of the year in the first and the last ten years, on the dates of a leap year
calendar&lt;-as.Date("2024-01-01")+0:365
season_first&lt;-tapply(aegean_mean[year%in%first_ten],day[year%in%first_ten],mean)
season_last&lt;-tapply(aegean_mean[year%in%last_ten],day[year%in%last_ten],mean)
# the share of the Aegean (by area) whose surface reached 26.5 °C on at least one day of a year
reached&lt;-sapply(min(years):last_year,function(y) {
  cells_reached&lt;-apply(sea[,year==y]&gt;=tropical,1,any)
  return(100*sum(weights[cells_reached])/sum(weights))
})
names(reached)&lt;-min(years):last_year
# the days of each year on which the mean of the whole Aegean reached 26.5 °C
tropical_days&lt;-tapply(aegean_mean&gt;=tropical,year,sum)
tropical_first&lt;-mean(tropical_days[as.character(first_ten)])
tropical_last&lt;-mean(tropical_days[as.character(last_ten)])
warmest_day&lt;-which.max(aegean_mean)
# the share of the Aegean (by area) whose August averaged 26.5 °C or more
august_first&lt;-rowMeans(sea[,month==8&amp;year%in%first_ten])
august_last&lt;-rowMeans(sea[,month==8&amp;year%in%last_ten])
share_first&lt;-100*sum(weights[august_first&gt;=tropical])/sum(weights)
share_last&lt;-100*sum(weights[august_last&gt;=tropical])/sum(weights)
coldest&lt;-which.min(by_month$last)</code></pre></div></div>
</details>
</div>
<p><strong>Not yet, but its summers are getting closer.</strong> No single temperature makes a sea tropical, but one number is often used: hurricanes need “water at least 26.5 degrees Celsius over a depth of 50 meters” (<a href="https://oceanservice.noaa.gov/facts/how-hurricanes-form.html">NOAA</a>). This record sees only the surface, which in summer is warmer than the water below it, so it can only say how often the surface of the Aegean is that warm.</p>
<p>More and more often. In an average year of 1982–1991, the surface reached 26.5 °C, on at least one day, in 7% of the Aegean; in 2016–2025, in 61%. The mean of the whole Aegean never reached 26.5 °C in 1982–1991; in 2016–2025 it did on 4.3 days a year. Its warmest day of all was 16 August 2015, at 27.3 °C.</p>
<p>The chart shows the average of each day of the year in the two periods: even the average day of 2016–2025 peaks at 25.7 °C, below 26.5.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14"><pre><code class="language-r">season&lt;-data.frame(date=calendar,first=as.numeric(season_first),last=as.numeric(season_last))
plot_ly(season,x=~date,y=~first,type="scatter",mode="lines",
        name=paste0(min(first_ten),"–",max(first_ten)),line=list(color=blue,width=2.5),
        hovertemplate=paste0(min(first_ten),"–",max(first_ten),
                             ", %{x|%e %B}: %{y:.1f} °C&lt;extra&gt;&lt;/extra&gt;")) %&gt;%
  add_trace(y=~last,name=paste0(min(last_ten),"–",last_year),line=list(color=greek_red,width=2.5),
            hovertemplate=paste0(min(last_ten),"–",last_year,
                                 ", %{x|%e %B}: %{y:.1f} °C&lt;extra&gt;&lt;/extra&gt;")) %&gt;%
  chart("The year of the Aegean: the average of each day, °C",
        paste0(oisst_source,": the mean of the Aegean's cells. The dotted line: 26.5 °C."),
        "°C",x_axis=list(tickformat="%b",dtick="M1",showgrid=FALSE),
        y_axis=list(range=c(floor(min(season_first)),max(tropical,max(season_last))+0.7)),
        shapes=list(list(type="line",xref="paper",x0=0,x1=1,y0=tropical,y1=tropical,
                         line=list(color=dark_gray,width=1,dash="dot"))),
        annotations=list(list(text="26.5 °C",xref="paper",x=0,y=tropical,xanchor="left",
                              yanchor="bottom",showarrow=FALSE,
                              font=list(size=11,color=dark_gray))),
        legend=legend_top,margin=list(t=100,b=90))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_AEGEAN_WARMING.html">Interactive chart: The year of the Aegean: the average of each day, °C</a></p>
</div>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15"><pre><code class="language-r"># the first and the last day of the year on which the average day of a period was at least as warm
# as a temperature, as dates of a leap year; NA if it never was
season_span&lt;-function(season,temperature) {
  above&lt;-which(season&gt;=temperature)
  result&lt;-if(length(above)==0) as.Date(c(NA,NA)) else calendar[range(above)]
  return(result)
}
span_text&lt;-function(span) {
  result&lt;-if(is.na(span[1])) "never" else
    paste0(trimws(format(span[1],"%e %B"))," to ",trimws(format(span[2],"%e %B"))," (",
           as.integer(diff(span))+1," days)")
  return(result)
}
warm_levels&lt;-c(20,22,24)
spans_first&lt;-lapply(warm_levels,function(level) season_span(season_first,level))
spans_last&lt;-lapply(warm_levels,function(level) season_span(season_last,level))
knitr::kable(data.frame(paste(warm_levels,"°C or more"),sapply(spans_first,span_text),
                        sapply(spans_last,span_text)),
             col.names=c("The average day",paste0(min(first_ten),"–",max(first_ten)),
                         paste0(min(last_ten),"–",last_year)),align="lll")</code></pre></div></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 39%">
<col style="width: 40%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">The average day</th>
<th style="text-align: left;">1982–1991</th>
<th style="text-align: left;">2016–2025</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">20 °C or more</td>
<td style="text-align: left;">4 June to 23 October (142 days)</td>
<td style="text-align: left;">28 May to 12 November (169 days)</td>
</tr>
<tr class="even">
<td style="text-align: left;">22 °C or more</td>
<td style="text-align: left;">21 June to 2 October (104 days)</td>
<td style="text-align: left;">11 June to 16 October (128 days)</td>
</tr>
<tr class="odd">
<td style="text-align: left;">24 °C or more</td>
<td style="text-align: left;">13 August to 14 August (2 days)</td>
<td style="text-align: left;">1 July to 20 September (82 days)</td>
</tr>
</tbody>
</table>
</div>
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16"><pre><code class="language-r"># how many days earlier the average day now reaches 22 °C, and how many days later it falls below
earlier&lt;-as.integer(spans_first[[2]][1]-spans_last[[2]][1])
later&lt;-as.integer(spans_last[[2]][2]-spans_first[[2]][2])</code></pre></div></div>
</details>
</div>
<p><strong>The warm season is longer</strong>, more at its end than at its start. In 2016–2025 the surface of an average day reached 22 °C on 11 June, 10 days earlier than in 1982–1991, and stayed there until 16 October, 14 days later. 24 °C, which the average day of 1982–1991 reached for 2 days, now lasts 82 days.</p>
<p>The maps show where. In August of 1982–1991, none of the Aegean averaged 26.5 °C or more; in 2016–2025, 14%.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17"><pre><code class="language-r"># steps of one degree, the same on both maps, from x.5 to x.5 °C so that 26.5 °C is a step
low&lt;-floor(min(august_first,august_last)-0.5)+0.5
high&lt;-ceiling(max(august_first,august_last)-0.5)+0.5
steps&lt;-colorRampPalette(c("#fff5eb","#fdd0a2","#fd8d3c","#d94801","#7f2704"))(high-low)
step_scale&lt;-do.call(c,lapply(seq_along(steps),function(i) list(list((i-1)/length(steps),steps[i]),
                                                               list(i/length(steps),steps[i]))))
hover_first&lt;-paste0(one(cells$lat[aegean]),"°N ",one(cells$lon[aegean]),"°E: ",
                    one(august_first)," °C")
hover_last&lt;-paste0(one(cells$lat[aegean]),"°N ",one(cells$lon[aegean]),"°E: ",one(august_last),
                   " °C")
left&lt;-map_axes(c(0,0.49))
right&lt;-map_axes(c(0.51,1),"x2","y2")
plot_ly() %&gt;%
  sea_map(august_first,hover_first,coloraxis="coloraxis") %&gt;%
  sea_map(august_last,hover_last,"x2","y2",coloraxis="coloraxis") %&gt;%
  chart("The Aegean in August, average of each cell",
        paste0(oisst_source,"; land: GISCO © EuroGeographics."),
        x_axis=left$x,y_axis=left$y,xaxis2=right$x,yaxis2=right$y,
        coloraxis=list(colorscale=step_scale,cmin=low,cmax=high,
                       colorbar=list(title=list(text="°C"),thickness=12,len=0.6,
                                     tickvals=seq(low,high,by=1))),
        annotations=list(list(text=paste0(min(first_ten),"–",max(first_ten)),x=0.245,y=1,
                              xref="paper",yref="paper",yanchor="bottom",showarrow=FALSE),
                         list(text=paste0(min(last_ten),"–",last_year),x=0.755,y=1,
                              xref="paper",yref="paper",yanchor="bottom",showarrow=FALSE)),
        plot_bgcolor=other_sea,margin=list(t=80,b=40,l=10,r=10),note_y=-0.02)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_AEGEAN_WARMING.html">Interactive chart: The Aegean in August, average of each cell</a></p>
</div>
</div>
<p>But the Aegean is far from tropical in winter. In March, its coldest month, it averaged 15.8 °C in 2016–2025, 1.3 °C more than in 1982–1991.</p>
<hr>
</section>
<section id="are-marine-heatwaves-more-common" class="level2">
<h2 class="anchored" data-anchor-id="are-marine-heatwaves-more-common">5. Are marine heatwaves more common?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18"><pre><code class="language-r"># the days of each category of heatwave in each year, in the average cell of the Aegean (by area)
heatwave_year&lt;-sapply(years,function(y) {
  in_year&lt;-category[,year==y,drop=FALSE]
  return(sapply(1:4,function(k) sum(weights*rowSums(in_year==k))/sum(weights)))
})
dimnames(heatwave_year)&lt;-list(names(category_colours),years)
heatwave_total&lt;-colSums(heatwave_year)
heatwave_first&lt;-mean(heatwave_total[as.character(first_ten)])
heatwave_last&lt;-mean(heatwave_total[as.character(last_ten)])
record&lt;-years[which.max(heatwave_total)]
# the share of those days that were strong or worse
stronger&lt;-function(period) {
  columns&lt;-as.character(period)
  result&lt;-100*sum(heatwave_year[2:4,columns])/sum(heatwave_year[,columns])
  return(result)
}</code></pre></div></div>
</details>
</div>
<p><strong>Much more common.</strong> In 1982–1991, an average place in the Aegean spent 6.6 days a year in a marine heatwave; in 2016–2025, 153 days. The most were in 2024: 269 days. 22% of the heatwave days of 2016–2025 were strong or worse, against 6% in 1982–1991.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19"><pre><code class="language-r">p&lt;-plot_ly()
for(k in 1:4) {
  p&lt;-p %&gt;%
    add_trace(x=years,y=heatwave_year[k,],type="bar",name=names(category_colours)[k],
              marker=list(color=category_colours[k]),
              hovertemplate=paste0("%{x}: %{y:.0f} days ",tolower(names(category_colours)[k]),
                                   "&lt;extra&gt;&lt;/extra&gt;"))
}
p %&gt;%
  chart("Days of marine heatwave, by category",
        paste0(oisst_source,": the days of each category in the cells of the Aegean, averaged by ",
               "area.&lt;br&gt;",max(years)," up to ",date_text(last_day),"."),
        "days a year",barmode="stack",bargap=0.15,legend=c(legend_top,list(traceorder="normal")),
        margin=list(t=100,b=100))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_AEGEAN_WARMING.html">Interactive chart: Days of marine heatwave, by category</a></p>
</div>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20"><pre><code class="language-r"># the heatwaves of the Aegean as a whole: their first and last days, length and peak
runs&lt;-rle(mean_heatwave)
ends&lt;-cumsum(runs$lengths)[runs$values]
starts&lt;-ends-runs$lengths[runs$values]+1
events&lt;-data.frame(start=dates[starts],end=dates[ends],days=ends-starts+1)
events$peak&lt;-sapply(seq_along(starts),function(i) max(anomaly[starts[i]:ends[i]]))
longest&lt;-events[order(-events$days),][1:5,]
# whether each of them took in a winter month
in_winter&lt;-sapply(1:5,function(i) {
  months&lt;-format(seq(longest$start[i],longest$end[i],by="day"),"%m")
  return(any(months%in%c("12","01","02")))
})
knitr::kable(data.frame(paste(date_text(longest$start),"–",date_text(longest$end)),longest$days,
                        paste0("+",one(longest$peak)," °C")),
             col.names=c("Heatwave of the whole Aegean","Days","Warmest day against the normal"),
             align="lrr",row.names=FALSE)</code></pre></div></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 47%">
<col style="width: 7%">
<col style="width: 44%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Heatwave of the whole Aegean</th>
<th style="text-align: right;">Days</th>
<th style="text-align: right;">Warmest day against the normal</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">28 August 2020 – 13 April 2021</td>
<td style="text-align: right;">229</td>
<td style="text-align: right;">+2.5 °C</td>
</tr>
<tr class="even">
<td style="text-align: left;">6 October 2023 – 30 April 2024</td>
<td style="text-align: right;">208</td>
<td style="text-align: right;">+2.9 °C</td>
</tr>
<tr class="odd">
<td style="text-align: left;">23 October 2025 – 12 April 2026</td>
<td style="text-align: right;">172</td>
<td style="text-align: right;">+2.4 °C</td>
</tr>
<tr class="even">
<td style="text-align: left;">13 November 2024 – 7 April 2025</td>
<td style="text-align: right;">146</td>
<td style="text-align: right;">+1.8 °C</td>
</tr>
<tr class="odd">
<td style="text-align: left;">10 December 2022 – 13 April 2023</td>
<td style="text-align: right;">125</td>
<td style="text-align: right;">+2.0 °C</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The whole Aegean, the mean of all its cells, went through 5 heatwaves in 1982–1991 and 53 in 2016–2025. The longest lasted 229 days, from 28 August 2020 to 13 April 2021; all five of the longest took in a winter, the season that warmed most. The year with most heatwave days, 2024:</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21"><pre><code class="language-r">in_record&lt;-year==record
flame&lt;-data.frame(date=dates[in_record],temperature=aegean_mean[in_record],
                  normal=mean_normal[in_record],threshold=mean_threshold[in_record],
                  heatwave=mean_heatwave[in_record])
flame$top&lt;-ifelse(flame$heatwave,pmax(flame$temperature,flame$threshold),flame$threshold)
# the heatwaves fill the space between the threshold and the temperature; the legend lists the
# lines first
plot_ly(flame,x=~date) %&gt;%
  add_trace(y=~threshold,type="scatter",mode="lines",name="Threshold (90%)",legendrank=3,
            line=list(color=category_colours[["Strong"]],width=1.5,dash="dot"),
            hoverinfo="skip") %&gt;%
  add_trace(y=~top,type="scatter",mode="lines",fill="tonexty",fillcolor="rgba(255,105,0,0.55)",
            line=list(width=0),name="Heatwave",legendrank=4,hoverinfo="skip") %&gt;%
  add_trace(y=~normal,type="scatter",mode="lines",name="Normal (1982–2011)",legendrank=2,
            line=list(color=blue,width=1.5),hoverinfo="skip") %&gt;%
  add_trace(y=~temperature,type="scatter",mode="lines",name=paste("Temperature in",record),
            legendrank=1,line=list(color="black",width=1.5),
            hovertemplate="%{x|%e %B}: %{y:.1f} °C&lt;extra&gt;&lt;/extra&gt;") %&gt;%
  chart(paste0("The Aegean in ",record,", °C"),
        paste0(oisst_source,": the mean of the Aegean's cells; normal and threshold of each day ",
               "from 1982–2011."),
        "°C",x_axis=list(tickformat="%b",dtick="M1",showgrid=FALSE),
        legend=c(legend_top,list(traceorder="normal")),margin=list(t=100,b=90))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_AEGEAN_WARMING.html">Interactive chart: The Aegean in 2024, °C</a></p>
</div>
</div>
<p><strong>Why against 1982–2011?</strong> The heatwaves here are measured against a fixed past, the first thirty years of the record, so the warming itself makes the sea cross the threshold more often. A normal that moved with the sea would count fewer heatwave days in the recent years, and would pick out only the weeks that are unusual even for a warmer Aegean. The two answer different questions: the fixed past says how much more often the life of the sea meets water warmer than it used to, the moving one how often the sea surprises us now.</p>
<hr>
</section>
<section id="so-what-does-it-mean" class="level2">
<h2 class="anchored" data-anchor-id="so-what-does-it-mean">So, what does it mean?</h2>
<p><strong>The Aegean is warmer, in every month and everywhere, and most of all in winter and autumn.</strong> Comparing 1982–1991 with 2016–2025:</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22"><pre><code class="language-r">august&lt;-which(by_month$month=="August")
measures&lt;-rbind(c("Mean of the year (°C)",one(first_mean),one(last_mean)),
                c("Mean of August (°C)",one(by_month$first[august]),one(by_month$last[august])),
                c(paste0("Mean of ",by_month$month[coldest]," (°C)"),one(by_month$first[coldest]),
                  one(by_month$last[coldest])),
                c("Days warmer than normal (%)",round(warmer_first),round(warmer_last)),
                c("Days at 26.5 °C or more, a year",one(tropical_first),one(tropical_last)),
                c("Days of marine heatwave, a year",one(heatwave_first),one(heatwave_last)))
knitr::kable(as.data.frame(measures),
             col.names=c("Measure",paste0(min(first_ten),"–",max(first_ten)),
                         paste0(min(last_ten),"–",last_year)),align="lrr",row.names=FALSE)</code></pre></div></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: left;">Measure</th>
<th style="text-align: right;">1982–1991</th>
<th style="text-align: right;">2016–2025</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Mean of the year (°C)</td>
<td style="text-align: right;">18.7</td>
<td style="text-align: right;">20.1</td>
</tr>
<tr class="even">
<td style="text-align: left;">Mean of August (°C)</td>
<td style="text-align: right;">23.8</td>
<td style="text-align: right;">25.4</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Mean of March (°C)</td>
<td style="text-align: right;">14.5</td>
<td style="text-align: right;">15.8</td>
</tr>
<tr class="even">
<td style="text-align: left;">Days warmer than normal (%)</td>
<td style="text-align: right;">29</td>
<td style="text-align: right;">94</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Days at 26.5 °C or more, a year</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">4.3</td>
</tr>
<tr class="even">
<td style="text-align: left;">Days of marine heatwave, a year</td>
<td style="text-align: right;">6.6</td>
<td style="text-align: right;">153.3</td>
</tr>
</tbody>
</table>
</div>
</div>
<ol type="1">
<li><strong>The sea is warmer</strong>: 1.4 °C over the year, 0.39 °C a decade.</li>
<li><strong>Winter and autumn warmed most</strong>: November and December by 1.9 °C, May and April by 0.8 °C.</li>
<li><strong>The warm season is longer</strong>: on an average day the surface is at 22 °C or more from 11 June to 16 October, against 21 June to 2 October in 1982–1991.</li>
<li><strong>It warmed everywhere</strong>: every cell of the grid, by 0.27 to 0.48 °C a decade.</li>
<li><strong>Its summers come closer to the tropics, its winters do not</strong>: the surface of 61% of the Aegean reaches 26.5 °C on at least one day a year, but March still averages 15.8 °C.</li>
<li><strong>Marine heatwaves have become common</strong>: 153 days a year, 42% of the year, instead of 6.6.</li>
</ol>
<p><strong>What this does not show.</strong> The record starts in 1981, when the satellites did, so it cannot say how warm the Aegean was before. It measures the surface only, not the water below, where most sea life lives. Its cells of a quarter of a degree cannot see small bays and harbors. And the mean of a sea hides its corners: a bay can be much warmer than the open sea around it.</p>
<p>For the air over Athens, see <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_ATHENS_HEAT.html">Athens Is Getting Hotter</a>; for the sea level, <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SEA_LEVEL.html">Is the Sea Rising at Piraeus?</a>; and for the world as a whole, the <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_CLIMATE_HIGHCHARTER.html">NASA GISS Global Temperature Anomaly</a>.</p>
<hr>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<ul>
<li>Huang, B., C. Liu, V. Banzon, E. Freeman, G. Graham, B. Hankins, T. Smith and H.-M. Zhang (2021), <a href="https://doi.org/10.1175/JCLI-D-20-0166.1">Improvements of the Daily Optimum Interpolation Sea Surface Temperature (DOISST) Version 2.1</a>, <em>Journal of Climate</em> 34, 2923–2939.</li>
<li>Huang, B., C. Liu, V.F. Banzon, E. Freeman, G. Graham, B. Hankins, T.M. Smith and H.-M. Zhang (2020), <a href="https://doi.org/10.25921/RE9P-PT57">NOAA 0.25-degree Daily Optimum Interpolation Sea Surface Temperature (OISST), Version 2.1</a>, NOAA National Centers for Environmental Information, accessed 29 November 2026: from NOAA’s <a href="https://coastwatch.pfeg.noaa.gov/erddap/griddap/ncdcOisst21Agg_LonPM180.html">ERDDAP server at CoastWatch</a>, and the days it lacks from the <a href="https://psl.noaa.gov/data/gridded/data.noaa.oisst.v2.highres.html">NOAA Physical Sciences Laboratory</a> (NOAA OI SST V2 High Resolution Dataset data provided by the NOAA PSL, Boulder, Colorado, USA, from their website at <a href="https://psl.noaa.gov">https://psl.noaa.gov</a>).</li>
<li>Reynolds, R.W., T.M. Smith, C. Liu, D.B. Chelton, K.S. Casey and M.G. Schlax (2007), <a href="https://doi.org/10.1175/2007JCLI1824.1">Daily high-resolution-blended analyses for sea surface temperature</a>, <em>Journal of Climate</em> 20, 5473–5496.</li>
<li>Hobday, A.J. and others (2016), <a href="https://doi.org/10.1016/j.pocean.2015.12.014">A hierarchical approach to defining marine heatwaves</a>, <em>Progress in Oceanography</em> 141, 227–238.</li>
<li>Hobday, A.J. and others (2018), <a href="https://doi.org/10.5670/oceanog.2018.205">Categorizing and naming marine heatwaves</a>, <em>Oceanography</em> 31(2), 162–173.</li>
<li>Schlegel, R.W. and A.J. Smit (2018), <a href="https://doi.org/10.21105/joss.00821">heatwaveR: A central algorithm for the detection of heatwaves and cold-spells</a>, <em>Journal of Open Source Software</em> 3(27), 821: the R package whose results the code of this page reproduces.</li>
<li>Flanders Marine Institute (2018), <a href="https://doi.org/10.14284/323">IHO Sea Areas, version 3</a>, from <a href="https://www.marineregions.org/">Marine Regions</a>.</li>
<li>NOAA National Ocean Service, <a href="https://oceanservice.noaa.gov/facts/how-hurricanes-form.html">How do hurricanes form?</a></li>
<li>GISCO (European Commission), <a href="https://ec.europa.eu/eurostat/web/gisco/geodata/statistical-units/territorial-units-statistics">NUTS regions</a> of 2024, © EuroGeographics for the administrative boundaries.</li>
</ul>
<hr>
<p><em>Rendered with R 4.6.2 · plotly · ncdf4 · sf</em></p>
<!-- -->
</section>
<p>This post first appeared on <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_AEGEAN_WARMING.html">Illustrations in R</a>, with its interactive charts and the full R code.</p>]]></content:encoded>
    </item>
    <item>
      <title>The Crowded Sky: Every Working Satellite Around the Earth</title>
      <link>https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SATELLITES.html</link>
      <guid isPermaLink="true">https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SATELLITES.html</guid>
      <pubDate>Sat, 28 Nov 2026 21:09:57 +0200</pubDate>
      <category>R</category>
      <category>Illustrations in R</category>
      <description>Every working satellite around the Earth on a 3D globe, placed from CelesTrak’s orbital data: how crowded the sky has become since Starlink, where the satellites fly, when they were launched, who owns them, and where Greece’s own satellites are.</description>
      <content:encoded><![CDATA[<p><em>Every working satellite around the Earth on a 3D globe, placed from CelesTrak’s orbital data: how crowded the sky has become since Starlink, where the satellites fly, when they were launched, who owns them, and where Greece’s own satellites are.</em></p>
<p><img src="https://sedzinfo.github.io/vignettes/illustration/social-card.png" alt="Illustrations in R" width="1200" height="630"></p>
<section id="what-is-this" class="level2">
<h2 class="anchored" data-anchor-id="what-is-this">What is this?</h2>
<p>Satellites carry telephone calls and television, watch the weather, the crops and the forests, guide ships, planes and cars, and, more and more since 2019, bring the internet to homes from low orbits. This story places every working satellite around the Earth at one moment, from the orbits that CelesTrak publishes, and asks five questions:</p>
<ol type="1">
<li><strong>How crowded is the sky?</strong></li>
<li><strong>Where do the satellites fly?</strong></li>
<li><strong>When were they launched?</strong></li>
<li><strong>Who owns them?</strong></li>
<li><strong>Where are Greece’s satellites?</strong></li>
</ol>
<p>The data are CelesTrak’s (Kelso 2026): the orbit of every working satellite, which it updates every two hours, and its catalog of every object put into orbit, with its owner and its launch date. They are downloaded when the page is rendered. The globes can be turned with the mouse and zoomed, and every satellite shows its name when the pointer is over it.</p>
<hr>
</section>
<section id="packages" class="level2">
<h2 class="anchored" data-anchor-id="packages">Packages</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1"><pre><code class="language-r"># install.packages(c("plotly","rnaturalearth","rnaturalearthdata","sf"))
library(plotly)
library(rnaturalearth)</code></pre></div></div>
</details>
</div>
</section>
<section id="the-data" class="level2">
<h2 class="anchored" data-anchor-id="the-data">The data</h2>
<p>An orbit is given by six numbers: its size, its shape, its tilt to the equator, how it is turned around the Earth’s axis and within its own plane, and where the satellite was on it at a given moment. From them, Kepler’s equation tells where the satellite is at any other moment; the page also turns each orbit a little every day, as the Earth’s flattened shape does (Vallado 2013). Each satellite is placed where it was when the orbits were downloaded. For most of them, whose orbits were measured a day or two before, that place is right to within some tens of kilometers: enough to see the whole sky at once, but not to find a satellite in the night sky, which takes the full model that the orbits are fitted with. The coastlines of the globes are Natural Earth’s.</p>
<p>CelesTrak counts a satellite as active, and this page as working, when it is operational, partly operational, kept as a backup or a spare, or on an extended mission.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2"><pre><code class="language-r"># CelesTrak updates the orbits every two hours and its catalog once or twice a day, and asks that
# each be downloaded at most once per update: a copy is kept on this computer, and downloaded again
# only when it is older than that
kept&lt;-tools::R_user_dir("illustration",which="cache")
dir.create(kept,recursive=TRUE,showWarnings=FALSE)
download_kept&lt;-function(url,name,hours) {
  file&lt;-file.path(kept,name)
  if(!file.exists(file)||difftime(Sys.time(),file.mtime(file),units="hours")&gt;hours) {
    temporary&lt;-tempfile()
    download.file(url,temporary,quiet=TRUE,mode="wb")
    file.copy(temporary,file,overwrite=TRUE)
  }
  return(file)
}
orbits_file&lt;-download_kept(paste0("https://celestrak.org/NORAD/elements/gp.php",
                                  "?GROUP=active&amp;FORMAT=csv"),"celestrak_active.csv",2)
catalogue_file&lt;-download_kept("https://celestrak.org/pub/satcat.csv","celestrak_satcat.csv",12)
# the orbit of every working satellite, with its owner and launch date from the catalog
sat&lt;-merge(read.csv(orbits_file),
           read.csv(catalogue_file)[,c("NORAD_CAT_ID","OWNER","LAUNCH_DATE")],by="NORAD_CAT_ID")
sat$launched&lt;-as.Date(sat$LAUNCH_DATE)
sat$year&lt;-as.integer(format(sat$launched,"%Y"))
# the moment of the page: when the orbits were downloaded, to the minute
moment&lt;-as.POSIXct(trunc(file.mtime(orbits_file),"mins"))
mu&lt;-398600.4418         # the Earth's gravity, km³/s²
earth_radius&lt;-6378.137  # at the equator, km
j2&lt;-1.08263e-3          # how much the Earth is flattened
# where satellites are at a moment, from their orbits, in kilometers from the center of the Earth
# on axes that turn with it: x towards longitude 0, y towards 90° East, z towards the North Pole.
# `shift` moves each satellite along its orbit by that angle, to draw the whole orbit
place&lt;-function(x,moment,shift=0) {
  epoch&lt;-as.POSIXct(x$EPOCH,format="%Y-%m-%dT%H:%M:%OS",tz="UTC")
  seconds&lt;-as.numeric(difftime(moment,epoch,units="secs"))
  motion&lt;-x$MEAN_MOTION*2*pi/86400             # radians a second
  size&lt;-(mu/motion^2)^(1/3)                    # half the longest width of the orbit, km
  e&lt;-x$ECCENTRICITY
  tilt&lt;-x$INCLINATION*pi/180
  # the Earth's flattening turns the plane of each orbit, and the orbit within its plane, a little
  # every day
  turn&lt;-1.5*motion*j2*(earth_radius/(size*(1-e^2)))^2
  node&lt;-x$RA_OF_ASC_NODE*pi/180-turn*cos(tilt)*seconds
  perigee&lt;-x$ARG_OF_PERICENTER*pi/180+turn/2*(5*cos(tilt)^2-1)*seconds
  anomaly&lt;-(x$MEAN_ANOMALY*pi/180+motion*seconds+shift)%%(2*pi)
  # Kepler's equation, solved by Newton's method
  eccentric&lt;-anomaly
  for(step in 1:20)
    eccentric&lt;-eccentric-(eccentric-e*sin(eccentric)-anomaly)/(1-e*cos(eccentric))
  distance&lt;-size*(1-e*cos(eccentric))
  angle&lt;-perigee+2*atan2(sqrt(1+e)*sin(eccentric/2),sqrt(1-e)*cos(eccentric/2))
  space_x&lt;-distance*(cos(node)*cos(angle)-sin(node)*sin(angle)*cos(tilt))
  space_y&lt;-distance*(sin(node)*cos(angle)+cos(node)*sin(angle)*cos(tilt))
  # how far the Earth has turned at that moment: Greenwich sidereal time
  days&lt;-as.numeric(moment)/86400-10957.5
  earth&lt;-((280.46061837+360.98564736629*days)%%360)*pi/180
  result&lt;-data.frame(x=cos(earth)*space_x+sin(earth)*space_y,
                     y=cos(earth)*space_y-sin(earth)*space_x,
                     z=distance*sin(angle)*sin(tilt),
                     height=distance-earth_radius,
                     mean_height=size-earth_radius)
  return(result)
}
sat&lt;-cbind(sat,place(sat,moment))
sat$tilt&lt;-sat$INCLINATION
sat$period&lt;-1440/sat$MEAN_MOTION   # minutes to go once around the Earth
# the large internet constellations, by the names of their satellites; Greece's satellites, by
# their owner (Hellas Sat 4 is shared with Saudi Arabia); and all the others
groups&lt;-c(Starlink="Starlink (SpaceX)",OneWeb="OneWeb (Eutelsat)",Kuiper="Kuiper (Amazon)",
          China="Qianfan and Guowang (China)",Other="Other satellites",
          Greece="Greece's satellites")
sat$group&lt;-"Other"
sat$group[grepl("^STARLINK",sat$OBJECT_NAME)]&lt;-"Starlink"
sat$group[grepl("^ONEWEB",sat$OBJECT_NAME)]&lt;-"OneWeb"
sat$group[grepl("^KUIPER",sat$OBJECT_NAME)]&lt;-"Kuiper"
sat$group[grepl("^QIANFAN|^HULIANWANG DIGUI",sat$OBJECT_NAME)]&lt;-"China"
sat$group[sat$OWNER%in%c("GREC","GRSA")]&lt;-"Greece"
sat$group&lt;-factor(sat$group,levels=names(groups))
count&lt;-table(sat$group)
# the owners, by CelesTrak's codes: countries, and organizations or companies of several countries
# (the codes without a name here keep their code). TBD: not yet known
owner_name&lt;-c(US="United States",PRC="China",UK="United Kingdom",CIS="Russia (CIS)",JPN="Japan",
              IT="Italy",IND="India",SKOR="South Korea",GER="Germany",FR="France",
              ESA="European Space Agency",SPN="Spain",CA="Canada",TURK="Türkiye",
              GREC="Greece",GRSA="Greece")
sat$owner&lt;-ifelse(sat$OWNER%in%names(owner_name),owner_name[sat$OWNER],sat$OWNER)
owners&lt;-sort(table(sat$owner[sat$OWNER!="TBD"]),decreasing=TRUE)</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3"><pre><code class="language-r">greek_red&lt;-"#d62728"
blue&lt;-"#1f77b4"
gray&lt;-"#9e9e9e"
light_gray&lt;-"#e3e3e3"
dark_gray&lt;-"#6b6b6b" # also the color of the notes and the labels
# a color for each group of satellites, the same on every chart; the five colors apart from gray
# were checked for color blindness
group_colour&lt;-c(Starlink=blue,OneWeb="#1b9e77",Kuiper="#c47f17",China="#e377c2",Other=gray,
                Greece=greek_red)
# the source of a chart, as a note under it, and the common layout; a globe has no x and y axes
chart&lt;-function(p,title,source,y_title="",x_title="",y_axis=list(),x_axis=list(),
                annotations=list(),margin=list(t=70,b=90),note_y=-0.16,...) {
  note&lt;-list(text=paste("Source:",source),xref="paper",yref="paper",x=0,y=note_y,xanchor="left",
             yanchor="top",showarrow=FALSE,font=list(size=11,color=dark_gray))
  result&lt;-layout(p,
                 title=list(text=title,x=0.02,xanchor="left",y=0.97,yanchor="top"),
                 margin=margin,
                 annotations=c(annotations,list(note)),
                 ...)
  if(nchar(paste0(y_title,x_title))&gt;0||length(c(y_axis,x_axis))&gt;0)
    result&lt;-layout(result,yaxis=modifyList(list(title=y_title),y_axis),
                   xaxis=modifyList(list(title=x_title),x_axis))
  result&lt;-config(result,displaylogo=FALSE)
  return(result)
}
legend_top&lt;-list(orientation="h",x=0,y=1.02,yanchor="bottom",itemsizing="constant")
# short labels of numbers and dates, and lists of names in words
number&lt;-function(x) {
  result&lt;-format(round(x),big.mark=",",trim=TRUE,scientific=FALSE)
  return(result)
}
ordinal&lt;-function(n) {
  suffix&lt;-ifelse(n%%100%in%11:13,"th",c("th","st","nd","rd",rep("th",6))[n%%10+1])
  result&lt;-paste0(n,suffix)
  return(result)
}
in_words&lt;-function(x) {
  result&lt;-if(length(x)&lt;2) x else paste(paste(x[-length(x)],collapse=", "),"and",x[length(x)])
  return(result)
}
count_words&lt;-function(n) {
  words&lt;-c("one","two","three","four","five","six","seven","eight","nine","ten")
  result&lt;-if(n&lt;=10) words[n] else number(n)
  return(result)
}
# names as they are written in a sentence: "the United States"; "Hellas Sat 4", which CelesTrak
# writes "HELLAS-SAT 4 &amp; SGS-1" (SGS-1 is the Saudi part of the satellite)
with_the&lt;-function(x) {
  result&lt;-ifelse(x%in%c("United States","United Kingdom"),paste("the",x),x)
  return(result)
}
hellas&lt;-function(x) {
  result&lt;-sub("^HELLAS-SAT ([0-9]+).*$","Hellas Sat \\1",x)
  return(result)
}
date_words&lt;-function(x) {
  result&lt;-paste(as.integer(format(x,"%d")),month.name[as.integer(format(x,"%m"))],format(x,"%Y"))
  return(result)
}
when&lt;-paste0(date_words(as.Date(moment)),", ",format(moment,"%H:%M",tz="UTC")," UTC")
# the Earth of the globes: a pale sphere, and Natural Earth's coastlines just above it
latitude&lt;-seq(-90,90,by=3)*pi/180
longitude&lt;-seq(-180,180,by=3)*pi/180
sphere_x&lt;-round(earth_radius*outer(cos(longitude),cos(latitude)))
sphere_y&lt;-round(earth_radius*outer(sin(longitude),cos(latitude)))
sphere_z&lt;-round(earth_radius*outer(rep(1,length(longitude)),sin(latitude)))
coastline&lt;-sf::st_coordinates(ne_coastline(scale=110,returnclass="sf"))
piece&lt;-apply(coastline[,grep("^L",colnames(coastline)),drop=FALSE],1,paste,collapse="-")
# the points of each piece of coast, with a gap after each piece
points&lt;-unlist(lapply(split(seq_along(piece),factor(piece,levels=unique(piece))),c,NA))
coast_lon&lt;-coastline[points,"X"]*pi/180
coast_lat&lt;-coastline[points,"Y"]*pi/180
coast&lt;-data.frame(x=round(1.003*earth_radius*cos(coast_lat)*cos(coast_lon)),
                  y=round(1.003*earth_radius*cos(coast_lat)*sin(coast_lon)),
                  z=round(1.003*earth_radius*sin(coast_lat)))
globe&lt;-function() {
  result&lt;-plot_ly() %&gt;%
    add_surface(x=sphere_x,y=sphere_y,z=sphere_z,colorscale=list(c(0,1),c("#eef2f6","#eef2f6")),
                showscale=FALSE,hoverinfo="skip",
                lighting=list(ambient=1,diffuse=0,specular=0,roughness=1,fresnel=0)) %&gt;%
    add_trace(data=coast,x=~x,y=~y,z=~z,type="scatter3d",mode="lines",hoverinfo="skip",
              line=list(color="#9aa8b6",width=2),showlegend=FALSE)
  return(result)
}
# the view of a globe: from above Greece, with the axes hidden and as long as each other, out to
# r km from the center of the Earth; and two buttons, to show the low orbits only or every orbit
view_range&lt;-function(r) {
  result&lt;-list("scene.xaxis.range"=c(-r,r),"scene.yaxis.range"=c(-r,r),
               "scene.zaxis.range"=c(-r,r))
  return(result)
}
above_greece&lt;-c(x=cos(38*pi/180)*cos(23.7*pi/180),y=cos(38*pi/180)*sin(23.7*pi/180),
                z=sin(38*pi/180))
globe_scene&lt;-function(r) {
  axis&lt;-list(range=c(-r,r),visible=FALSE)
  result&lt;-list(xaxis=axis,yaxis=axis,zaxis=axis,aspectmode="cube",dragmode="turntable",
               camera=list(eye=as.list(1.2*above_greece)))
  return(result)
}
low_range&lt;-8500
all_range&lt;-45000
zoom_buttons&lt;-list(list(type="buttons",direction="right",x=0,y=0.02,xanchor="left",
                        yanchor="bottom",
                        buttons=list(list(label="Low orbits",method="relayout",
                                          args=list(view_range(low_range))),
                                     list(label="All orbits",method="relayout",
                                          args=list(view_range(all_range))))))</code></pre></div></div>
</details>
</div>
<hr>
</section>
<section id="how-crowded-is-the-sky" class="level2">
<h2 class="anchored" data-anchor-id="how-crowded-is-the-sky">1. How crowded is the sky?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4"><pre><code class="language-r">total&lt;-nrow(sat)
starlink_height&lt;-median(sat$mean_height[sat$group=="Starlink"])
# the other internet constellations, the largest first
others&lt;-sort(count[c("OneWeb","Kuiper","China")],decreasing=TRUE)
other_words&lt;-c(OneWeb="Eutelsat's OneWeb (%s)",Kuiper="Amazon's Kuiper (%s)",
               China="China's Qianfan and Guowang (%s together)")
low&lt;-sat$mean_height&lt;2000</code></pre></div></div>
</details>
</div>
<p><strong>Most of them belong to one company.</strong> On 29 November 2026, 14:36 UTC, CelesTrak listed 16,929 working satellites around the Earth. 11,184 of them, 66%, were SpaceX’s Starlink satellites, which bring the internet to homes, ships and planes from about 470 km up. The next largest internet constellations had far fewer: Eutelsat’s OneWeb (651), China’s Qianfan and Guowang (524 together) and Amazon’s Kuiper (427).</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5"><pre><code class="language-r">p&lt;-globe()
for(g in names(groups)[count&gt;0])
  p&lt;-add_trace(p,data=sat[sat$group==g,],x=~round(x),y=~round(y),z=~round(z),type="scatter3d",
               mode="markers",name=paste0(groups[[g]],": ",number(count[[g]])),
               text=~OBJECT_NAME,customdata=~round(height),
               marker=list(color=group_colour[[g]],size=if(g=="Greece") 5 else 2,
                           line=list(width=0)))
p&lt;-style(p,hovertemplate="&lt;b&gt;%{text}&lt;/b&gt;&lt;br&gt;%{customdata:,} km up&lt;extra&gt;&lt;/extra&gt;")
chart(p,paste("Every working satellite,",when),
      "CelesTrak: the orbits of the active satellites, each placed where it was at that moment",
      scene=globe_scene(low_range),legend=legend_top,updatemenus=zoom_buttons,
      margin=list(t=110,b=50,l=0,r=0),note_y=0)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SATELLITES.html">Interactive chart: Every working satellite, 29 November 2026, 14:36 UTC</a></p>
</div>
</div>
<p>At this scale most of the satellites hug the Earth: 95% fly less than 2,000 km up, under a third of the Earth’s radius above the ground. <strong>All orbits</strong> shows the others, out to the geostationary ring, about 36,000 km up.</p>
<hr>
</section>
<section id="where-do-the-satellites-fly" class="level2">
<h2 class="anchored" data-anchor-id="where-do-the-satellites-fly">2. Where do the satellites fly?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6"><pre><code class="language-r">band&lt;-floor(sat$mean_height[low]/100)*100
busiest_band&lt;-as.numeric(names(which.max(table(band))))
middle&lt;-sat$mean_height&gt;=2000&amp;sat$mean_height&lt;35000
navigation&lt;-grepl("NAVSTAR|GSAT0|GLONASS|BEIDOU",sat$OBJECT_NAME)
geostationary&lt;-abs(sat$mean_height-35786)&lt;200&amp;sat$tilt&lt;20
sun_synchronous&lt;-low&amp;sat$tilt&gt;96&amp;sat$tilt&lt;100</code></pre></div></div>
</details>
</div>
<p><strong>Most of them in a thin shell close to the Earth.</strong> 16,132 satellites, 95%, fly less than 2,000 km up, in low orbits; 10,703 of them between 400 and 500 km alone. There a satellite goes around the Earth in about an hour and a half: in 94 minutes, for a Starlink satellite. Further out, 210 fly between 2,000 and 35,000 km up, most of them the navigation satellites of GPS, Galileo, GLONASS and BeiDou, about 20,000 km up. And 541 sit in the geostationary ring, 35,786 km above the equator, where one turn takes a day: each stays above the same place on the Earth.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7"><pre><code class="language-r">p&lt;-plot_ly()
for(g in names(groups)[count&gt;0])
  p&lt;-add_trace(p,data=sat[sat$group==g,],x=~round(tilt,2),y=~round(mean_height),
               type="scattergl",mode="markers",name=groups[[g]],text=~OBJECT_NAME,
               marker=list(color=group_colour[[g]],size=if(g=="Greece") 8 else 4,opacity=0.6))
p&lt;-style(p,hovertemplate=paste0("&lt;b&gt;%{text}&lt;/b&gt;&lt;br&gt;%{y:,} km up on average,",
                                " orbit tilted %{x:.1f}°&lt;extra&gt;&lt;/extra&gt;"))
# labels for the main kinds of orbit, at the middle of their satellites (a log axis takes the
# logarithm of the height)
orbit_label&lt;-function(rows,text,ax,ay) {
  result&lt;-list(x=median(sat$tilt[rows]),y=log10(median(sat$mean_height[rows])),text=text,
               showarrow=TRUE,arrowhead=0,ax=ax,ay=ay,arrowcolor=dark_gray,
               font=list(size=12,color=dark_gray))
  return(result)
}
station&lt;-sat$OBJECT_NAME=="ISS (ZARYA)"
labels&lt;-list(orbit_label(geostationary,"Geostationary ring",70,-25),
             orbit_label(navigation&amp;middle,"Navigation satellites",80,-30),
             orbit_label(sun_synchronous,"Sun-synchronous orbits",20,65))
if(any(station))
  labels&lt;-c(labels,list(orbit_label(station,"International Space Station",40,-80)))
heights&lt;-c(200,500,1000,2000,5000,10000,20000,50000,100000)
chart(p,"Every working satellite by the tilt and the height of its orbit",
      "CelesTrak: the average height and the tilt of the orbit of each active satellite",
      "Average height above the Earth, km","Tilt of the orbit to the equator, degrees",
      y_axis=list(type="log",tickvals=heights,ticktext=number(heights)),
      x_axis=list(range=c(-3,ceiling(max(sat$tilt)/10)*10)),annotations=labels,
      legend=legend_top,margin=list(t=100,b=90),note_y=-0.13)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SATELLITES.html">Interactive chart: Every working satellite by the tilt and the height of its orbit</a></p>
</div>
</div>
<p>Each point is a satellite. The large constellations stand in columns, each a set of orbits of the same tilt at a few heights. The column at about 98° holds orbits that pass over every place at the same hour of the day: <em>sun-synchronous</em> orbits, which Earth-observation satellites use so that the light falls the same way in every picture (Vallado 2013). A tilt above 90° means that the satellite goes around the Earth against its turn, from east to west.</p>
<hr>
</section>
<section id="when-were-they-launched" class="level2">
<h2 class="anchored" data-anchor-id="when-were-they-launched">3. When were they launched?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8"><pre><code class="language-r">since_2019&lt;-mean(sat$year&gt;=2019)
per_year&lt;-table(sat$year)
top_year&lt;-as.integer(names(which.max(per_year)))
top_starlink&lt;-mean(sat$group[sat$year==top_year]=="Starlink")
oldest&lt;-sat[sat$launched==min(sat$launched),]
this_year&lt;-as.integer(format(moment,"%Y",tz="UTC"))</code></pre></div></div>
</details>
</div>
<p><strong>Almost all of them in the last few years.</strong> 93% of the working satellites were launched in 2019 or later. More of those launched in 2025 are at work than of any other year: 4,288, 73% of them Starlink’s. The oldest Starlink satellites still at work went up in 2019, and the oldest of all the working satellites, Calsphere 1 and Calsphere 2, in 1964.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9"><pre><code class="language-r">years&lt;-min(sat$year):max(sat$year)
p&lt;-plot_ly()
for(g in names(groups)[count&gt;0]) {
  x&lt;-data.frame(year=years,satellites=as.vector(table(factor(sat$year[sat$group==g],
                                                              levels=years))))
  p&lt;-add_trace(p,data=x,x=~year,y=~satellites,type="bar",name=groups[[g]],
               marker=list(color=group_colour[[g]]),
               hovertemplate=paste0(groups[[g]],", launched in %{x}: %{y:,}&lt;extra&gt;&lt;/extra&gt;"))
}
chart(p,"Working satellites by the year they were launched",
      paste0("CelesTrak's satellite catalogue. ",this_year,": up to ",date_words(as.Date(moment))),
      "Satellites",y_axis=list(tickformat=","),barmode="stack",bargap=0.1,
      legend=c(legend_top,list(traceorder="normal")),margin=list(t=110,b=80),note_y=-0.12)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SATELLITES.html">Interactive chart: Working satellites by the year they were launched</a></p>
</div>
</div>
<p>Satellites in low orbits last only some years: the thin air up there slows them down, and they fall back and burn up. So the bars of the earlier years count only the satellites that are still at work, not all those that were launched.</p>
<hr>
</section>
<section id="who-owns-them" class="level2">
<h2 class="anchored" data-anchor-id="who-owns-them">4. Who owns them?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10"><pre><code class="language-r">us&lt;-owners[["United States"]]
greek_count&lt;-owners[["Greece"]]
greek_rank&lt;-sum(owners&gt;greek_count)+1
tied&lt;-sum(owners==greek_count)&gt;1</code></pre></div></div>
</details>
</div>
<p><strong>Mostly the United States.</strong> 12,679 of the working satellites, 75%, belong to the United States, most of them Starlink’s. Then come China, with 1,607, and the United Kingdom, with 699. CelesTrak’s catalog names 97 owners of working satellites: countries, and also organizations and companies that work across countries, such as the European Space Agency. Greece comes 24th, with 25 satellites, counting the one it shares with Saudi Arabia.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11"><pre><code class="language-r"># the largest owners, and Greece, in boxes of their own; within an owner, a box for each
# constellation
shown&lt;-unique(c(names(owners)[1:14],"Greece"))
sat$box&lt;-ifelse(sat$owner%in%shown&amp;sat$OWNER!="TBD",sat$owner,"Other owners or not yet known")
boxes&lt;-aggregate(list(satellites=rep(1,nrow(sat))),list(owner=sat$box,group=sat$group),sum)
owner_total&lt;-tapply(boxes$satellites,boxes$owner,sum)
divided&lt;-names(which(tapply(boxes$group,boxes$owner,function(g) any(!g%in%c("Other","Greece")))))
inside&lt;-boxes[boxes$owner%in%divided,]
short&lt;-c(Starlink="Starlink",OneWeb="OneWeb",Kuiper="Kuiper",China="Qianfan and Guowang",
         Other="Other satellites",Greece="Greece")
owner_colour&lt;-ifelse(names(owner_total)%in%divided,light_gray,
                     ifelse(names(owner_total)=="Greece",greek_red,gray))
tree&lt;-data.frame(id=c("all",names(owner_total),paste(inside$owner,inside$group)),
                 parent=c("",rep("all",length(owner_total)),inside$owner),
                 label=c("All working satellites",names(owner_total),
                         short[as.character(inside$group)]),
                 satellites=c(total,owner_total,inside$satellites),
                 colour=c("white",owner_colour,group_colour[as.character(inside$group)]))
p&lt;-plot_ly(tree,type="treemap",ids=~id,parents=~parent,labels=~label,values=~satellites,
           branchvalues="total",marker=list(colors=~colour),texttemplate="%{label}&lt;br&gt;%{value:,}",
           hovertemplate=paste0("%{label}: %{value:,} satellites,",
                                " %{percentRoot:.1%} of all&lt;extra&gt;&lt;/extra&gt;"))
# a box too small for its name at a readable size shows it only on hover
chart(p,"Working satellites by owner",
      "CelesTrak's satellite catalogue: the owner of each active satellite. CIS: Russia",
      uniformtext=list(minsize=10,mode="hide"),margin=list(t=50,b=50,l=0,r=0),note_y=0)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SATELLITES.html">Interactive chart: Working satellites by owner</a></p>
</div>
</div>
<p>Each box is as large as the number of satellites it holds; Greece’s is the small red one. A click on an owner opens its box, and a box too small for its name shows it when the pointer is over it.</p>
<hr>
</section>
<section id="where-are-greeces-satellites" class="level2">
<h2 class="anchored" data-anchor-id="where-are-greeces-satellites">5. Where are Greece’s satellites?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12"><pre><code class="language-r">greek&lt;-sat[sat$group=="Greece",]
greek&lt;-greek[order(greek$launched,greek$OBJECT_NAME),]
large&lt;-greek[greek$mean_height&gt;30000,]
small&lt;-greek[greek$mean_height&lt;2000,]
shared&lt;-greek$OBJECT_NAME[greek$OWNER=="GRSA"]
# where the geostationary ones stay: the longitude below them
large$east&lt;-round(atan2(large$y,large$x)*180/pi)
large$where&lt;-paste0(abs(large$east),"° ",ifelse(large$east&lt;0,"West","East"))
level&lt;-large[large$tilt&lt;1,]
tilted&lt;-large[large$tilt&gt;=1,]</code></pre></div></div>
</details>
</div>
<p><strong>For many years, three large satellites; since 2025, 22 small ones too.</strong> Greece owns 24 working satellites and shares one more with Saudi Arabia, Hellas Sat 4. Until 23 June 2025, its working satellites were the three communication satellites of Hellas Sat, launched in 2003, 2017 and 2019, in the geostationary ring. Hellas Sat 3 and Hellas Sat 4 sit together above the equator at 39° East. Hellas Sat 2 is still listed as working, but its orbit is now tilted by 7.8°, so it swings north and south of the equator every day.</p>
<p>Since then, 22 small satellites have joined them, the last on 1 October 2026. They fly between 470 and 590 km up, all of them in sun-synchronous orbits, and go around the Earth in about 95 minutes. Most of them were built under the Greek National Small Satellite Programme, which Greece funds through the EU’s Recovery and Resilience Facility and ESA carries out for its Ministry of Digital Governance (ESA 2026a). Among them are two ICEYE radar satellites, launched at the end of 2025, and the four FOREST satellites of the Hellenic Fire System, which OroraTech built to spot wildfires by their heat and which went up on 3 May 2026 (ESA 2026b).</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13"><pre><code class="language-r"># each orbit as a line of 121 points, with a gap after it
steps&lt;-seq(0,2*pi,length.out=121)
orbit_line&lt;-function(i) {
  result&lt;-rbind(place(greek[rep(i,length(steps)),],moment,steps)[,c("x","y","z")],NA)
  return(result)
}
paths&lt;-do.call(rbind,lapply(seq_len(nrow(greek)),orbit_line))
greek$label&lt;-paste0("&lt;b&gt;",greek$OBJECT_NAME,"&lt;/b&gt;&lt;br&gt;launched ",date_words(greek$launched),
                    "&lt;br&gt;",number(greek$height)," km up")
p&lt;-globe() %&gt;%
  add_trace(data=paths,x=~round(x),y=~round(y),z=~round(z),type="scatter3d",mode="lines",
            name="Their orbits",line=list(color="rgba(214,39,40,0.45)",width=2),
            hoverinfo="skip") %&gt;%
  add_trace(data=greek,x=~round(x),y=~round(y),z=~round(z),type="scatter3d",mode="markers",
            name="Greece's satellites",text=~label,marker=list(color=greek_red,size=5),
            hovertemplate="%{text}&lt;extra&gt;&lt;/extra&gt;")
chart(p,paste("Greece's satellites and their orbits,",when),
      paste0("CelesTrak: the active satellites owned by Greece, and ",hellas(shared),
             ", shared with Saudi Arabia"),
      scene=globe_scene(low_range),legend=legend_top,updatemenus=zoom_buttons,
      margin=list(t=100,b=50,l=0,r=0),note_y=0)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SATELLITES.html">Interactive chart: Greece&#x27;s satellites and their orbits, 29 November 2026, 14:36 UTC</a></p>
</div>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14"><pre><code class="language-r">knitr::kable(data.frame(Satellite=greek$OBJECT_NAME,
                        Launched=date_words(greek$launched),
                        `Average height, km`=number(greek$mean_height),
                        `Tilt, degrees`=format(round(greek$tilt,1),nsmall=1),
                        `Minutes to go around the Earth`=number(greek$period),
                        check.names=FALSE),
             align="llrrr")</code></pre></div></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 25%">
<col style="width: 15%">
<col style="width: 17%">
<col style="width: 12%">
<col style="width: 28%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Satellite</th>
<th style="text-align: left;">Launched</th>
<th style="text-align: right;">Average height, km</th>
<th style="text-align: right;">Tilt, degrees</th>
<th style="text-align: right;">Minutes to go around the Earth</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">HELLAS-SAT 2</td>
<td style="text-align: left;">13 May 2003</td>
<td style="text-align: right;">35,787</td>
<td style="text-align: right;">7.8</td>
<td style="text-align: right;">1,436</td>
</tr>
<tr class="even">
<td style="text-align: left;">HELLAS-SAT 3</td>
<td style="text-align: left;">28 June 2017</td>
<td style="text-align: right;">35,787</td>
<td style="text-align: right;">0.1</td>
<td style="text-align: right;">1,436</td>
</tr>
<tr class="odd">
<td style="text-align: left;">HELLAS-SAT 4 &amp; SGS-1</td>
<td style="text-align: left;">5 February 2019</td>
<td style="text-align: right;">35,787</td>
<td style="text-align: right;">0.1</td>
<td style="text-align: right;">1,436</td>
</tr>
<tr class="even">
<td style="text-align: left;">DUTHSAT-2</td>
<td style="text-align: left;">23 June 2025</td>
<td style="text-align: right;">473</td>
<td style="text-align: right;">97.5</td>
<td style="text-align: right;">94</td>
</tr>
<tr class="odd">
<td style="text-align: left;">ICEYE-X59</td>
<td style="text-align: left;">28 November 2025</td>
<td style="text-align: right;">564</td>
<td style="text-align: right;">97.5</td>
<td style="text-align: right;">96</td>
</tr>
<tr class="even">
<td style="text-align: left;">ICEYE-X60</td>
<td style="text-align: left;">28 November 2025</td>
<td style="text-align: right;">535</td>
<td style="text-align: right;">97.4</td>
<td style="text-align: right;">95</td>
</tr>
<tr class="odd">
<td style="text-align: left;">MICE-1</td>
<td style="text-align: left;">28 November 2025</td>
<td style="text-align: right;">505</td>
<td style="text-align: right;">97.4</td>
<td style="text-align: right;">95</td>
</tr>
<tr class="even">
<td style="text-align: left;">PHASMA-DIRAC</td>
<td style="text-align: left;">28 November 2025</td>
<td style="text-align: right;">479</td>
<td style="text-align: right;">97.4</td>
<td style="text-align: right;">94</td>
</tr>
<tr class="odd">
<td style="text-align: left;">PHASMA-LAMARR</td>
<td style="text-align: left;">28 November 2025</td>
<td style="text-align: right;">484</td>
<td style="text-align: right;">97.4</td>
<td style="text-align: right;">94</td>
</tr>
<tr class="even">
<td style="text-align: left;">ERMIS-1</td>
<td style="text-align: left;">30 March 2026</td>
<td style="text-align: right;">506</td>
<td style="text-align: right;">97.5</td>
<td style="text-align: right;">95</td>
</tr>
<tr class="odd">
<td style="text-align: left;">ERMIS-2</td>
<td style="text-align: left;">30 March 2026</td>
<td style="text-align: right;">498</td>
<td style="text-align: right;">97.5</td>
<td style="text-align: right;">95</td>
</tr>
<tr class="even">
<td style="text-align: left;">ERMIS-3</td>
<td style="text-align: left;">30 March 2026</td>
<td style="text-align: right;">505</td>
<td style="text-align: right;">97.5</td>
<td style="text-align: right;">95</td>
</tr>
<tr class="odd">
<td style="text-align: left;">OPTISAT</td>
<td style="text-align: left;">30 March 2026</td>
<td style="text-align: right;">505</td>
<td style="text-align: right;">97.5</td>
<td style="text-align: right;">95</td>
</tr>
<tr class="even">
<td style="text-align: left;">PEAKSAT</td>
<td style="text-align: left;">30 March 2026</td>
<td style="text-align: right;">502</td>
<td style="text-align: right;">97.5</td>
<td style="text-align: right;">95</td>
</tr>
<tr class="odd">
<td style="text-align: left;">FOREST-16 (SOWITASGOHT)</td>
<td style="text-align: left;">3 May 2026</td>
<td style="text-align: right;">588</td>
<td style="text-align: right;">97.7</td>
<td style="text-align: right;">96</td>
</tr>
<tr class="even">
<td style="text-align: left;">FOREST-17 (TELPERION)</td>
<td style="text-align: left;">3 May 2026</td>
<td style="text-align: right;">588</td>
<td style="text-align: right;">97.7</td>
<td style="text-align: right;">96</td>
</tr>
<tr class="odd">
<td style="text-align: left;">FOREST-18 (MANGOSHRIKHAND)</td>
<td style="text-align: left;">3 May 2026</td>
<td style="text-align: right;">588</td>
<td style="text-align: right;">97.7</td>
<td style="text-align: right;">96</td>
</tr>
<tr class="even">
<td style="text-align: left;">FOREST-19 (PATADASTRA)</td>
<td style="text-align: left;">3 May 2026</td>
<td style="text-align: right;">588</td>
<td style="text-align: right;">97.7</td>
<td style="text-align: right;">96</td>
</tr>
<tr class="odd">
<td style="text-align: left;">HELIOS</td>
<td style="text-align: left;">3 May 2026</td>
<td style="text-align: right;">500</td>
<td style="text-align: right;">97.4</td>
<td style="text-align: right;">95</td>
</tr>
<tr class="even">
<td style="text-align: left;">SELENE</td>
<td style="text-align: left;">3 May 2026</td>
<td style="text-align: right;">501</td>
<td style="text-align: right;">97.4</td>
<td style="text-align: right;">95</td>
</tr>
<tr class="odd">
<td style="text-align: left;">HYPERION GR-1</td>
<td style="text-align: left;">7 July 2026</td>
<td style="text-align: right;">595</td>
<td style="text-align: right;">97.7</td>
<td style="text-align: right;">97</td>
</tr>
<tr class="even">
<td style="text-align: left;">SIDLOC PQ-03</td>
<td style="text-align: left;">1 October 2026</td>
<td style="text-align: right;">510</td>
<td style="text-align: right;">97.4</td>
<td style="text-align: right;">95</td>
</tr>
<tr class="odd">
<td style="text-align: left;">SIDLOC PQ-04</td>
<td style="text-align: left;">1 October 2026</td>
<td style="text-align: right;">511</td>
<td style="text-align: right;">97.4</td>
<td style="text-align: right;">95</td>
</tr>
<tr class="even">
<td style="text-align: left;">SIDLOC PQ-05</td>
<td style="text-align: left;">1 October 2026</td>
<td style="text-align: right;">511</td>
<td style="text-align: right;">97.4</td>
<td style="text-align: right;">95</td>
</tr>
<tr class="odd">
<td style="text-align: left;">SIDLOC PQ-06</td>
<td style="text-align: left;">1 October 2026</td>
<td style="text-align: right;">511</td>
<td style="text-align: right;">97.4</td>
<td style="text-align: right;">95</td>
</tr>
</tbody>
</table>
</div>
</div>
<hr>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<ul>
<li>Kelso, T. S. (2026), CelesTrak: the <a href="https://celestrak.org/NORAD/elements/">orbits of the active satellites</a> (general perturbations data, CSV), the <a href="https://celestrak.org/satcat/search.php">satellite catalog</a> (SATCAT, CSV), its <a href="https://celestrak.org/satcat/sources.php">owner codes</a> and <a href="https://celestrak.org/satcat/status.php">status codes</a>, and the <a href="https://celestrak.org/usage-policy.php">usage policy</a> on how often to download them.</li>
<li>Vallado, D. A. (2013), <em>Fundamentals of Astrodynamics and Applications</em>, 4th edition, Microcosm Press: Kepler’s equation, the turning of orbits by the Earth’s flattening, and sun-synchronous orbits.</li>
<li>Natural Earth, <a href="https://www.naturalearthdata.com/downloads/110m-physical-vectors/110m-coastline/">coastlines at 1:110 million</a>, through the rnaturalearth package, version 1.2.0.</li>
<li>ESA (2026a), <a href="https://resilience.esa.int/archives/news/greek-connectivity-programme-implemented-by-esa-proceeds-with-satellite-commissioning-and-launches">Greek Connectivity Programme implemented by ESA proceeds with satellite commissioning and launches</a>, 13 February 2026.</li>
<li>ESA (2026b), <a href="https://www.esa.int/Applications/Observing_the_Earth/Hellenic_Fire_System_satellites_launched_for_Greece">Hellenic Fire System satellites launched for Greece</a>, 4 May 2026.</li>
</ul>
<hr>
<p><em>Rendered with R 4.6.2 · plotly · rnaturalearth</em></p>
<!-- -->
</section>
<p>This post first appeared on <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_SATELLITES.html">Illustrations in R</a>, with its interactive charts and the full R code.</p>]]></content:encoded>
    </item>
    <item>
      <title>Who Learns Most at 15? PISA Scores of Greece, Europe and the World Since 2000</title>
      <link>https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_PISA.html</link>
      <guid isPermaLink="true">https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_PISA.html</guid>
      <pubDate>Sat, 28 Nov 2026 18:48:24 +0200</pubDate>
      <category>R</category>
      <category>Illustrations in R</category>
      <description>The OECD’s PISA tests of 15-year-olds in reading, mathematics and science since 2000, from the students’ data in the learningtower package and from Eurostat: who learns most, where Greece stands in the EU, who rose and who fell, girls and boys, family background, and what PISA 2025 adds.</description>
      <content:encoded><![CDATA[<p><em>The OECD’s PISA tests of 15-year-olds in reading, mathematics and science since 2000, from the students’ data in the learningtower package and from Eurostat: who learns most, where Greece stands in the EU, who rose and who fell, girls and boys, family background, and what PISA 2025 adds.</em></p>
<p><img src="https://sedzinfo.github.io/vignettes/illustration/social-card.png" alt="Illustrations in R" width="1200" height="630"></p>
<section id="what-is-this" class="level2">
<h2 class="anchored" data-anchor-id="what-is-this">What is this?</h2>
<p>Every three years since 2000, the OECD has tested 15-year-olds around the world in <strong>reading, mathematics and science</strong>: its Programme for International Student Assessment, <strong>PISA</strong>. The test does not ask what students remember of their lessons, but whether they can use what they have learned on problems they have not met before. The round of 2021 was put off to 2022 by the pandemic. This story asks seven questions:</p>
<ol type="1">
<li><strong>Who learns most at 15?</strong></li>
<li><strong>Where does Greece stand in Europe?</strong></li>
<li><strong>Who rose and who fell since 2000?</strong></li>
<li><strong>What happened in 2022?</strong></li>
<li><strong>Do girls or boys do better?</strong></li>
<li><strong>Does family background matter?</strong></li>
<li><strong>What does PISA 2025 add?</strong></li>
</ol>
<p>The data are the OECD’s own: the scores of every student who took the test from 2000 to 2022, which the <strong>learningtower</strong> package prepares for R (Wang and others 2026), and, for 2025, the shares of students below the basic level of PISA that <strong>Eurostat</strong> publishes for the EU. They are downloaded when the page is rendered.</p>
<p><strong>PISA 2025.</strong> The OECD published the results of its 2025 round on 8 September 2026. Its student data are not yet in learningtower, so the scores below stop at 2022; question 7 shows the part of 2025 that Eurostat already publishes.</p>
<hr>
</section>
<section id="packages" class="level2">
<h2 class="anchored" data-anchor-id="packages">Packages</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1"><pre><code class="language-r"># install.packages(c("learningtower","eurostat","plotly"))
library(learningtower)
library(eurostat)
library(plotly)</code></pre></div></div>
</details>
</div>
</section>
<section id="the-data" class="level2">
<h2 class="anchored" data-anchor-id="the-data">The data</h2>
<p>Each student answers only some of the questions, so PISA gives a student not one score but several <em>plausible values</em>, drawn from what their answers say about them; learningtower keeps the first. Weighted by the number of 15-year-olds that each student stands for, they give the mean score of a country. The means here differ by a point or two from those the OECD publishes, which use all the plausible values.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2"><pre><code class="language-r"># the students of every round of PISA in learningtower, with their scores, sex, weight and family
# background. A round is a download of 2 to 10 MB from the package's repository on GitHub; a
# download that fails is tried again
rounds&lt;-c(2000,2003,2006,2009,2012,2015,2018,2022)
load_round&lt;-function(year) {
  x&lt;-NULL
  for(attempt in 1:4) {
    x&lt;-load_student(year)
    if(!is.null(x))
      break
    Sys.sleep(10)
  }
  if(is.null(x))
    stop("Could not download the students of PISA ",year," from learningtower")
  result&lt;-data.frame(year=year,country=as.character(x$country),sex=tolower(x$gender),
                     read=x$read,math=x$math,science=x$science,weight=x$stu_wgt,escs=x$escs)
  return(result)
}
students&lt;-do.call(rbind,lapply(rounds,load_round))
students$country[students$country=="ROM"]&lt;-"ROU" # Romania's code in 2000
last&lt;-max(rounds)
# the countries of the EU; the others by the names that learningtower gives them
eu&lt;-c(AUT="Austria",BEL="Belgium",BGR="Bulgaria",HRV="Croatia",CYP="Cyprus",CZE="Czechia",
      DNK="Denmark",EST="Estonia",FIN="Finland",FRA="France",DEU="Germany",GRC="Greece",
      HUN="Hungary",IRL="Ireland",ITA="Italy",LVA="Latvia",LTU="Lithuania",LUX="Luxembourg",
      MLT="Malta",NLD="Netherlands",POL="Poland",PRT="Portugal",ROU="Romania",SVK="Slovakia",
      SVN="Slovenia",ESP="Spain",SWE="Sweden")
country_name&lt;-c(eu,setNames(countrycode$country_name,countrycode$country))
# the mean score of a group of students, each counted with their weight: the number of
# 15-year-olds of their country that they stand for
weighted_mean&lt;-function(score,weight) {
  ok&lt;-!is.na(score)
  result&lt;-sum(score[ok]*weight[ok])/sum(weight[ok])
  return(result)
}
subjects&lt;-c(read="Reading",math="Mathematics",science="Science")
# the mean scores of the students of a country in a round
country_means&lt;-function(x) {
  result&lt;-data.frame(country=x$country[1],year=x$year[1],read=weighted_mean(x$read,x$weight),
                     math=weighted_mean(x$math,x$weight),
                     science=weighted_mean(x$science,x$weight))
  return(result)
}
means&lt;-do.call(rbind,lapply(split(students,list(students$country,students$year),drop=TRUE),
                            country_means))
means$name&lt;-unname(country_name[means$country])
# a subject is compared over time from the round in which it was first the main subject of the
# test, when its scale was set
first_round&lt;-c(read=2000,math=2003,science=2006)
for(subject in names(subjects))
  means[means$year&lt;first_round[subject],subject]&lt;-NA
# the EU countries over time, without the results that the OECD does not compare over time: the
# Netherlands in 2000, when too few of its schools took part; Austria in 2009, when opposition to
# the test may have lowered the students' effort; Spain in 2018, when the test was not run
# properly in some of its regions
excluded&lt;-c("NLD 2000","AUT 2009","ESP 2018")
trend&lt;-means[means$country%in%names(eu)&amp;!paste(means$country,means$year)%in%excluded,]
trend&lt;-trend[order(trend$country,trend$year),]
# the EU line of the charts: the average, each country counted once, of the other EU countries
# with comparable results in every round since 2006, when most of them took part
recent&lt;-trend[trend$year&gt;=2006,]
peers&lt;-setdiff(names(which(table(recent$country)==length(unique(recent$year)))),"GRC")
eu_line&lt;-aggregate(cbind(read,math,science)~year,recent[recent$country%in%peers,],mean)
greek_trend&lt;-trend[trend$country=="GRC",]
# the last round: every country and economy, the EU countries, Greece and the other EU countries
latest&lt;-means[means$year==last&amp;!is.na(means$math),]
europe&lt;-latest[latest$country%in%names(eu),]
greece&lt;-europe[europe$country=="GRC",]
others&lt;-europe[europe$country!="GRC",]
# the place of Greece among a group of countries in a subject: 1 is the highest mean score
place&lt;-function(x,subject) {
  result&lt;-match("GRC",x$country[order(-x[[subject]])])
  return(result)
}
# how far Greece is below the average of the other EU countries, in points
gap&lt;-sapply(names(subjects),function(subject) mean(others[[subject]])-greece[[subject]])
# the students of the EU countries in the last round, country by country
europe_students&lt;-students[students$year==last&amp;students$country%in%names(eu),]
by_country&lt;-split(europe_students,europe_students$country)
# the score that a share p of the students do not exceed, the students counted with their weights
weighted_quantile&lt;-function(score,weight,p) {
  ok&lt;-!is.na(score)
  sorted&lt;-order(score[ok])
  share&lt;-cumsum(weight[ok][sorted])/sum(weight[ok])
  result&lt;-score[ok][sorted][which(share&gt;=p)[1]]
  return(result)
}
# the share of the students of a country at the top levels of mathematics, 5 and 6 (607 points or
# more), and the scores that its weakest tenth do not exceed and its best tenth reach
spread&lt;-function(x) {
  result&lt;-data.frame(country=x$country[1],top=100*weighted_mean(x$math&gt;=606.99,x$weight),
                     weakest=weighted_quantile(x$math,x$weight,0.1),
                     best=weighted_quantile(x$math,x$weight,0.9))
  return(result)
}
spreads&lt;-do.call(rbind,lapply(by_country,spread))
greek_spread&lt;-spreads[spreads$country=="GRC",]
other_spreads&lt;-spreads[spreads$country!="GRC",]
# the mean scores of the girls and of the boys of a country in a round, in columns such as
# read_girls, and by how many points the girls are ahead (a negative number: the boys are ahead)
sex_means&lt;-function(x) {
  girls&lt;-x$sex%in%"female"
  boys&lt;-x$sex%in%"male"
  result&lt;-data.frame(country=x$country[1],year=x$year[1])
  for(subject in names(subjects)) {
    result[[paste0(subject,"_girls")]]&lt;-weighted_mean(x[[subject]][girls],x$weight[girls])
    result[[paste0(subject,"_boys")]]&lt;-weighted_mean(x[[subject]][boys],x$weight[boys])
    result[[subject]]&lt;-result[[paste0(subject,"_girls")]]-result[[paste0(subject,"_boys")]]
  }
  return(result)
}
sexes&lt;-do.call(rbind,lapply(by_country,sex_means))
other_sexes&lt;-sexes[sexes$country!="GRC",]
greek_students&lt;-students[students$country=="GRC",]
greek_sexes&lt;-do.call(rbind,lapply(split(greek_students,greek_students$year),sex_means))
# the quarter of family background of each student of a country, from 1 (the least advantaged) to
# 4 (the most), by PISA's index of economic, social and cultural status; each quarter holds a
# quarter of the country's 15-year-olds
background_quarter&lt;-function(escs,weight) {
  result&lt;-rep(NA,length(escs))
  ok&lt;-which(!is.na(escs))
  sorted&lt;-ok[order(escs[ok])]
  result[sorted]&lt;-pmin(4,ceiling(4*cumsum(weight[sorted])/sum(weight[sorted])))
  return(result)
}
# the mean score in mathematics of the least and of the most advantaged quarter of a country
background_means&lt;-function(x) {
  quarter&lt;-background_quarter(x$escs,x$weight)
  result&lt;-data.frame(country=x$country[1],
                     least=weighted_mean(x$math[quarter%in%1],x$weight[quarter%in%1]),
                     most=weighted_mean(x$math[quarter%in%4],x$weight[quarter%in%4]))
  return(result)
}
background&lt;-do.call(rbind,lapply(by_country,background_means))
background$gap&lt;-background$most-background$least
other_background&lt;-background[background$country!="GRC",]
# Eurostat: the share of 15-year-olds below level 2, the basic level of PISA, in every EU country
# and in the EU as a whole, up to the latest round
eurostat_values&lt;-function(id,filters) {
  x&lt;-get_eurostat(id,filters=filters,time_format="num",cache=FALSE)
  result&lt;-as.data.frame(x[!is.na(x$values),])
  return(result)
}
low&lt;-eurostat_values("sdg_04_40",list(sex="T",unit="PC"))
low$subject&lt;-c(READ="read",EF461="math",SCI="science")[low$field]
low_last&lt;-max(low$time)
low_before&lt;-max(low$time[low$time&lt;low_last])
low_value&lt;-function(geo,subject,year) {
  result&lt;-low$values[low$geo==geo&amp;low$subject==subject&amp;low$time==year]
  return(result)
}</code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3"><pre><code class="language-r">greek_red&lt;-"#d62728"
blue&lt;-"#1f77b4"
gray&lt;-"#9e9e9e"
light_gray&lt;-"#cccccc"
dark_gray&lt;-"#6b6b6b" # also the color of the notes and the labels
# a color and a marker for each subject, the same on every chart
subject_colour&lt;-c(read="#c47f17",math="#2a9d8f",science="#7b5ea7")
subject_symbol&lt;-c(read="diamond",math="circle",science="square")
# the source of a chart, as a note under it, and the common layout
chart&lt;-function(p,title,source,y_title="",x_title="",y_axis=list(),x_axis=list(),
                annotations=list(),margin=list(t=70,b=90),note_y=-0.16,...) {
  note&lt;-list(text=paste("Source:",source),xref="paper",yref="paper",x=0,y=note_y,xanchor="left",
             yanchor="top",showarrow=FALSE,font=list(size=11,color=dark_gray))
  result&lt;-layout(p,
                 title=list(text=title,x=0.02,xanchor="left",y=0.97,yanchor="top"),
                 yaxis=modifyList(list(title=y_title),y_axis),
                 xaxis=modifyList(list(title=x_title),x_axis),
                 margin=margin,
                 annotations=c(annotations,list(note)),
                 ...) %&gt;%
    config(displaylogo=FALSE)
  return(result)
}
legend_top&lt;-list(orientation="h",x=0,y=1.02,yanchor="bottom")
# short labels of numbers, and lists of names in words
number&lt;-function(x) {
  result&lt;-format(round(x),big.mark=",",trim=TRUE)
  return(result)
}
ordinal&lt;-function(n) {
  suffix&lt;-ifelse(n%%100%in%11:13,"th",c("th","st","nd","rd",rep("th",6))[n%%10+1])
  result&lt;-paste0(n,suffix)
  return(result)
}
in_words&lt;-function(x) {
  result&lt;-if(length(x)&lt;2) x else paste(paste(x[-length(x)],collapse=", "),"and",x[length(x)])
  return(result)
}
# the label of a country on a chart of countries, Greece in bold, and a band behind its row
bold_greece&lt;-function(name) {
  result&lt;-ifelse(name=="Greece","&lt;b&gt;Greece&lt;/b&gt;",name)
  return(result)
}
greece_band&lt;-function(labels) {
  row&lt;-match("&lt;b&gt;Greece&lt;/b&gt;",labels)-1
  result&lt;-list(type="rect",xref="paper",x0=0,x1=1,yref="y",y0=row-0.5,y1=row+0.5,
               fillcolor=greek_red,opacity=0.1,line=list(width=0),layer="below")
  return(result)
}
# a label with a line to the point of a country on the chart of the world
point_label&lt;-function(x,code,ax,ay) {
  row&lt;-x[x$country==code,]
  result&lt;-list(x=row$math,y=row$read,text=row$name,showarrow=TRUE,arrowhead=0,ax=ax,ay=ay,
               arrowcolor=dark_gray,font=list(size=12,color=dark_gray))
  return(result)
}</code></pre></div></div>
</details>
</div>
<hr>
</section>
<section id="who-learns-most-at-15" class="level2">
<h2 class="anchored" data-anchor-id="who-learns-most-at-15">1. Who learns most at 15?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4"><pre><code class="language-r">best&lt;-latest[order(-latest$math),]
first_five&lt;-best$name[1:5]
# the economies of East Asia in PISA: if the first five are all among them, the text says so
east_asia&lt;-c("SGP","MAC","TAP","HKG","JPN","KOR","QCN","QCH","QCI","CHN","VNM")
first_europe&lt;-europe[which.max(europe$math),]</code></pre></div></div>
</details>
</div>
<p><strong>The 15-year-olds of East Asia.</strong> In 2022, the highest mean scores in mathematics were those of Singapore, Macao (China), Chinese Taipei, Hong Kong (China) and Japan. Estonia, the first country of Europe, came 7th, 65 points behind Singapore. Greece came 44th of the 80 countries and economies in mathematics, 41st in reading and 44th in science.</p>
<p>The scores are points on a scale on which the 15-year-olds of the OECD’s countries averaged 500, with about two thirds of them between 400 and 600, in the round in which each subject was first the main one of the test: 2000 for reading, 2003 for mathematics and 2006 for science. The OECD counts a fall of 15 points as about three quarters of a year of learning (OECD 2023), so <strong>20 points are roughly a year of school</strong>.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5"><pre><code class="language-r">world&lt;-latest
world$group&lt;-ifelse(world$country=="GRC","Greece",
                    ifelse(world$country%in%names(eu),"Other EU countries","The rest of the world"))
groups&lt;-c(`The rest of the world`=gray,`Other EU countries`=blue,Greece=greek_red)
p&lt;-plot_ly()
for(group in names(groups))
  p&lt;-add_trace(p,data=world[world$group==group,],x=~math,y=~read,type="scatter",mode="markers",
               name=group,text=~name,customdata=~science,
               marker=list(color=groups[[group]],size=ifelse(group=="Greece",13,9),
                           line=list(color="white",width=1)),
               hovertemplate=paste0("&lt;b&gt;%{text}&lt;/b&gt;&lt;br&gt;Mathematics %{x:.0f}&lt;br&gt;",
                                    "Reading %{y:.0f}&lt;br&gt;Science %{customdata:.0f}&lt;extra&gt;&lt;/extra&gt;"))
labels&lt;-list(point_label(latest,"GRC",50,35),point_label(latest,best$country[1],-70,20),
             point_label(latest,first_europe$country,-60,-35))
chart(p,paste0("Mean scores in mathematics and reading, ",last),
      "learningtower (OECD PISA): the first plausible value of every student, weighted",
      "Reading","Mathematics",annotations=labels,legend=legend_top,margin=list(t=100,b=90))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_PISA.html">Interactive chart: Mean scores in mathematics and reading, 2022</a></p>
</div>
</div>
<p>Countries that do well in one subject do well in the others: across the 80 countries and economies, the mean scores in mathematics and in reading have a correlation of 0.94, and those in mathematics and in science of 0.98.</p>
<hr>
</section>
<section id="where-does-greece-stand-in-europe" class="level2">
<h2 class="anchored" data-anchor-id="where-does-greece-stand-in-europe">2. Where does Greece stand in Europe?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6"><pre><code class="language-r"># the EU countries below Greece in a subject, from the highest score to the lowest
below_greece&lt;-function(subject) {
  x&lt;-europe[europe[[subject]]&lt;greece[[subject]],]
  result&lt;-x$name[order(-x[[subject]])]
  return(result)
}
below&lt;-lapply(names(subjects),below_greece)
same_below&lt;-all(sapply(below,identical,below[[1]]))
places&lt;-sapply(names(subjects),function(subject) place(europe,subject))
# the country just below Greece in mathematics, and by how many points
next_below&lt;-europe[europe$math&lt;greece$math,]
next_below&lt;-next_below[which.max(next_below$math),]</code></pre></div></div>
</details>
</div>
<p><strong>Near the bottom.</strong> Of the 25 EU countries in the data of 2022, Greece came 23rd in mathematics, 23rd in reading and 23rd in science: only Romania and Bulgaria scored lower in all three. (Cyprus is not in learningtower’s data, and Luxembourg did not take part in 2022.) Differences of a few points are within the margin of error of the test, such as the 3 points between Greece and Romania in mathematics.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7"><pre><code class="language-r">europe$average&lt;-rowMeans(europe[,names(subjects)])
ranked&lt;-europe[order(europe$average),]
ranked$label&lt;-factor(bold_greece(ranked$name),levels=bold_greece(ranked$name))
p&lt;-plot_ly()
for(subject in names(subjects))
  p&lt;-add_trace(p,data=ranked,x=ranked[[subject]],y=~label,type="scatter",mode="markers",
               name=subjects[[subject]],
               marker=list(color=subject_colour[[subject]],symbol=subject_symbol[[subject]],
                           size=10),
               hovertemplate=paste0("%{y}, ",tolower(subjects[[subject]]),
                                    ": %{x:.0f}&lt;extra&gt;&lt;/extra&gt;"))
chart(p,paste0("Mean scores of the EU countries, ",last),
      "learningtower (OECD PISA). Cyprus is not in the data; Luxembourg did not take part in 2022.",
      legend=legend_top,margin=list(l=110,t=100,b=90),note_y=-0.08,
      shapes=list(greece_band(levels(ranked$label))))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_PISA.html">Interactive chart: Mean scores of the EU countries, 2022</a></p>
</div>
</div>
<p>Greece’s mean was 45 points below the average of the other 24 EU countries in mathematics, 36 in reading and 44 in science: by the OECD’s rule, about 2 years of school. The gap is widest at the top. Only 2.2% of Greek 15-year-olds reached the top levels of mathematics, 5 and 6, which take 607 points or more: the smallest share in the EU, against 8.2% on average in the other EU countries. The best tenth of the Greek students scored 543 points or more in mathematics, against 595 on average in the other EU countries; the weakest tenth scored 327 or less, against 357. The students below the basic level of PISA are in <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_GREEK_WORKFORCE.html">Greece at Work</a>.</p>
<hr>
</section>
<section id="who-rose-and-who-fell-since-2000" class="level2">
<h2 class="anchored" data-anchor-id="who-rose-and-who-fell-since-2000">3. Who rose and who fell since 2000?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8"><pre><code class="language-r">greek_score&lt;-function(subject,year) {
  result&lt;-greek_trend[[subject]][greek_trend$year==year]
  return(result)
}
eu_score&lt;-function(subject,year) {
  result&lt;-eu_line[[subject]][eu_line$year==year]
  return(result)
}
# Greece's best round in each subject
peak&lt;-sapply(names(subjects),function(subject)
  greek_trend$year[which.max(greek_trend[[subject]])])
# the change in mathematics of the EU countries with results in 2003 and in the last round
since_2003&lt;-merge(trend[trend$year==2003&amp;!is.na(trend$math),c("country","name","math")],
                  trend[trend$year==last,c("country","math")],by="country",
                  suffixes=c("_2003","_last"))
since_2003$change&lt;-since_2003$math_last-since_2003$math_2003
largest_fall&lt;-since_2003[which.min(since_2003$change),]
# how far Greece was below the EU line in its best round (2006 in science, the first of the line)
# and in the last
behind&lt;-function(subject,year) {
  result&lt;-eu_score(subject,year)-greek_score(subject,year)
  return(result)
}
from&lt;-c(read=unname(peak["read"]),math=unname(peak["math"]),science=2006)
widened&lt;-all(sapply(names(subjects),function(subject)
  behind(subject,last)&gt;behind(subject,from[subject])))</code></pre></div></div>
</details>
</div>
<p><strong>Greece did best in 2009, and has fallen since.</strong> Its mean in reading went from 474 in 2000 to 482 in 2009 and 437 in 2022; in mathematics, from 445 in 2003 to 465 in 2009 and 431 in 2022. In science its best round was its first, 2006, with 473; in 2022 it scored 441.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9"><pre><code class="language-r"># one panel of the chart: the EU countries in gray, the EU line in blue and Greece in red
trend_panel&lt;-function(subject,legend) {
  x&lt;-trend[!is.na(trend[[subject]]),]
  y&lt;-as.formula(paste0("~",subject))
  codes&lt;-setdiff(unique(x$country),"GRC")
  p&lt;-plot_ly()
  for(code in codes)
    p&lt;-add_trace(p,data=x[x$country==code,],x=~year,y=y,type="scatter",mode="lines",
                 name="Other EU countries",legendgroup="other",showlegend=legend&amp;code==codes[1],
                 line=list(color=light_gray,width=1),text=~name,
                 hovertemplate="%{text}, %{x}: %{y:.0f}&lt;extra&gt;&lt;/extra&gt;")
  p&lt;-add_trace(p,data=eu_line,x=~year,y=y,type="scatter",mode="lines+markers",
               name=paste("Average of",length(peers),"other EU countries"),legendgroup="eu",
               showlegend=legend,line=list(color=blue,width=2),marker=list(color=blue,size=6),
               hovertemplate="EU average, %{x}: %{y:.0f}&lt;extra&gt;&lt;/extra&gt;")
  p&lt;-add_trace(p,data=x[x$country=="GRC",],x=~year,y=y,type="scatter",mode="lines+markers",
               name="Greece",legendgroup="greece",showlegend=legend,
               line=list(color=greek_red,width=3),marker=list(color=greek_red,size=7),
               hovertemplate="Greece, %{x}: %{y:.0f}&lt;extra&gt;&lt;/extra&gt;")
  return(p)
}
panels&lt;-lapply(names(subjects),function(subject) trend_panel(subject,subject=="read"))
p&lt;-subplot(panels,nrows=3,shareX=TRUE,margin=0.05)
# the names of the subjects above their panels, and the same range of scores in every panel
range_all&lt;-range(unlist(trend[,names(subjects)]),na.rm=TRUE)
y_range&lt;-list(range=c(10*floor(range_all[1]/10)-5,10*ceiling(range_all[2]/10)+5))
titles&lt;-lapply(seq_along(subjects),function(i)
  list(text=paste0("&lt;b&gt;",subjects[i],"&lt;/b&gt;"),xref="paper",yref="paper",x=0,xanchor="left",
       y=p$x$layout[[c("yaxis","yaxis2","yaxis3")[i]]]$domain[2],yanchor="bottom",
       showarrow=FALSE))
chart(p,"Mean scores since 2000: Greece, the EU and every EU country",
      paste0("learningtower (OECD PISA). EU: the ",length(peers)," other EU countries with ",
             "comparable results in every round since 2006"),
      y_axis=y_range,x_axis=list(tickvals=rounds),annotations=titles,legend=legend_top,
      margin=list(t=110,b=80),note_y=-0.07,yaxis2=y_range,yaxis3=y_range)</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_PISA.html">Interactive chart: Mean scores since 2000: Greece, the EU and every EU country</a></p>
</div>
</div>
<p><strong>The EU fell too, but less, so Greece fell further behind.</strong> Greece was 25 points below the EU line in mathematics in 2009 and 45 in 2022; in reading, 5 points in 2009 and 37 in 2022; in science, 24 in 2006 and 45 in 2022. Greece is not the country that fell most, though: between 2003 and 2022 mathematics fell in 15 of the 18 EU countries with results in both rounds, by 14 points in Greece and most in Finland, by 60.</p>
<hr>
</section>
<section id="what-happened-in-2022" class="level2">
<h2 class="anchored" data-anchor-id="what-happened-in-2022">4. What happened in 2022?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10"><pre><code class="language-r"># the EU countries with comparable results in 2018 and in the last round, and how their mean
# scores changed
change&lt;-merge(trend[trend$year==2018,c("country","name",names(subjects))],
              trend[trend$year==last,c("country",names(subjects))],by="country",
              suffixes=c("_before","_after"))
for(subject in names(subjects))
  change[[subject]]&lt;-change[[paste0(subject,"_after")]]-change[[paste0(subject,"_before")]]
fell&lt;-sapply(names(subjects),function(subject) sum(change[[subject]]&lt;0))
greek_change&lt;-change[change$country=="GRC",]
other_change&lt;-change[change$country!="GRC",]</code></pre></div></div>
</details>
</div>
<p><strong>Scores fell everywhere in mathematics.</strong> Between 2018 and 2022, the mean in mathematics fell in all 24 EU countries with comparable results in both rounds, by 16 points on average in the others and by 20 in Greece. Reading fell in 22 of them, by 20 points in Greece, and science in 13, by 11 in Greece.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11"><pre><code class="language-r">change&lt;-change[order(-change$math),]
change$label&lt;-factor(bold_greece(change$name),levels=bold_greece(change$name))
p&lt;-plot_ly()
for(greek in c(FALSE,TRUE)) {
  x&lt;-change[(change$country=="GRC")==greek,]
  colour&lt;-if(greek) greek_red else dark_gray
  p&lt;-add_segments(p,data=x,x=~math_before,xend=~math_after,y=~label,yend=~label,
                  line=list(color=colour,width=2),showlegend=FALSE,hoverinfo="none")
  p&lt;-add_trace(p,data=x,x=~math_before,y=~label,type="scatter",mode="markers",name="2018",
               legendgroup="before",showlegend=!greek,
               marker=list(symbol="circle-open",size=10,color=colour,line=list(width=2)),
               hovertemplate="%{y}, 2018: %{x:.0f}&lt;extra&gt;&lt;/extra&gt;")
  p&lt;-add_trace(p,data=x,x=~math_after,y=~label,type="scatter",mode="markers",
               name=as.character(last),legendgroup="after",showlegend=!greek,
               marker=list(size=10,color=colour),customdata=~math,
               hovertemplate=paste0("%{y}, ",last,": %{x:.0f} (%{customdata:+.0f})&lt;extra&gt;&lt;/extra&gt;"))
}
chart(p,paste0("Mean score in mathematics, 2018 and ",last),
      "learningtower (OECD PISA). Spain is left out: its results of 2018 are not comparable.",
      legend=legend_top,margin=list(l=110,t=100,b=90),note_y=-0.08,
      y_axis=list(categoryorder="array",categoryarray=levels(change$label)),
      shapes=list(greece_band(levels(change$label))))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_PISA.html">Interactive chart: Mean score in mathematics, 2018 and 2022</a></p>
</div>
</div>
<p>2022 was the first round after the pandemic closed the schools. The OECD calls the fall in mathematics across its countries, almost 15 points, unprecedented; but it also finds that the pandemic explains only part of it. In reading and science, scores had begun to fall well before the pandemic, and the countries whose schools stayed closed longer did not clearly fall more than those that opened them sooner (OECD 2023).</p>
<hr>
</section>
<section id="do-girls-or-boys-do-better" class="level2">
<h2 class="anchored" data-anchor-id="do-girls-or-boys-do-better">5. Do girls or boys do better?</h2>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12"><pre><code class="language-r">greek_sex&lt;-sexes[sexes$country=="GRC",]
boys_ahead&lt;-sum(sexes$math&lt;0)
# the reading of Greek girls and boys in Greece's best round and in the last
girls_fall&lt;-greek_sexes$read_girls[greek_sexes$year==peak["read"]]-
  greek_sexes$read_girls[greek_sexes$year==last]
boys_fall&lt;-greek_sexes$read_boys[greek_sexes$year==peak["read"]]-
  greek_sexes$read_boys[greek_sexes$year==last]</code></pre></div></div>
</details>
</div>
<p><strong>Girls read better everywhere; boys are a little ahead in mathematics in most countries.</strong> In 2022 the girls scored higher than the boys in reading in all 25 EU countries, by 27 points on average in the others and by 25 in Greece. In mathematics the boys were ahead in 21 of the 25, by 7 points on average in the others and by 7 in Greece. In science the two are within 10 points of each other in 19 of the 25 countries; in Greece the girls were 11 points ahead.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13"><pre><code class="language-r">sexes$name&lt;-unname(eu[sexes$country])
sexes&lt;-sexes[order(sexes$read),]
sexes$label&lt;-factor(bold_greece(sexes$name),levels=bold_greece(sexes$name))
p&lt;-plot_ly()
for(subject in names(subjects))
  p&lt;-add_trace(p,data=sexes,x=sexes[[subject]],y=~label,type="scatter",mode="markers",
               name=subjects[[subject]],
               marker=list(color=subject_colour[[subject]],symbol=subject_symbol[[subject]],
                           size=10),
               hovertemplate=paste0("%{y}, ",tolower(subjects[[subject]]),
                                    ": %{x:+.0f}&lt;extra&gt;&lt;/extra&gt;"))
sides&lt;-list(list(text="← Boys ahead",x=0,xanchor="right",xshift=-6,y=1,yanchor="bottom",
                 xref="x",yref="paper",showarrow=FALSE,font=list(color=dark_gray)),
            list(text="Girls ahead →",x=0,xanchor="left",xshift=6,y=1,yanchor="bottom",
                 xref="x",yref="paper",showarrow=FALSE,font=list(color=dark_gray)))
chart(p,paste0("Girls' mean score minus boys', ",last,", points"),"learningtower (OECD PISA)",
      annotations=sides,legend=list(orientation="h",x=0,y=1.06,yanchor="bottom"),
      margin=list(l=110,t=120,b=90),note_y=-0.08,
      shapes=list(greece_band(levels(sexes$label)),
                  list(type="line",x0=0,x1=0,yref="paper",y0=0,y1=1,
                       line=list(color=dark_gray,width=1))))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_PISA.html">Interactive chart: Girls&#x27; mean score minus boys&#x27;, 2022, points</a></p>
</div>
</div>
<p>In Greece the gap in reading has narrowed, from 48 points in 2009 to 25 in 2022, but not because the boys caught up: the girls fell further. Since 2009 the girls’ mean in reading has fallen by 55 points, and the boys’ by 33.</p>
<hr>
</section>
<section id="does-family-background-matter" class="level2">
<h2 class="anchored" data-anchor-id="does-family-background-matter">6. Does family background matter?</h2>
<p>PISA measures the family background of each student with an index of economic, social and cultural status, from the education and jobs of the parents and the things the family has at home, such as books. Here the students of each country are split by that index into four quarters, from the least to the most advantaged.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14"><pre><code class="language-r">greek_background&lt;-background[background$country=="GRC",]
background_place&lt;-rank(background$gap)[background$country=="GRC"]
others_average&lt;-mean(others$math)</code></pre></div></div>
</details>
</div>
<p><strong>Everywhere, but less in Greece.</strong> In the other EU countries, the most advantaged quarter of the students scored 98 points more in mathematics than the least advantaged, on average: about 5 years of school. In Greece the gap was 75 points, the 4th smallest of the 25 countries.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15"><pre><code class="language-r">background$name&lt;-unname(eu[background$country])
background&lt;-background[order(background$gap),]
background$label&lt;-factor(bold_greece(background$name),levels=bold_greece(background$name))
p&lt;-plot_ly()
for(greek in c(FALSE,TRUE)) {
  x&lt;-background[(background$country=="GRC")==greek,]
  colour&lt;-if(greek) greek_red else dark_gray
  p&lt;-add_segments(p,data=x,x=~least,xend=~most,y=~label,yend=~label,
                  line=list(color=colour,width=2),showlegend=FALSE,hoverinfo="none")
  p&lt;-add_trace(p,data=x,x=~least,y=~label,type="scatter",mode="markers",
               name="Least advantaged quarter",legendgroup="least",showlegend=!greek,
               marker=list(symbol="circle-open",size=10,color=colour,line=list(width=2)),
               hovertemplate="%{y}, least advantaged quarter: %{x:.0f}&lt;extra&gt;&lt;/extra&gt;")
  p&lt;-add_trace(p,data=x,x=~most,y=~label,type="scatter",mode="markers",
               name="Most advantaged quarter",legendgroup="most",showlegend=!greek,
               marker=list(size=10,color=colour),customdata=~gap,
               hovertemplate=paste0("%{y}, most advantaged quarter: %{x:.0f}",
                                    " (%{customdata:.0f} points more)&lt;extra&gt;&lt;/extra&gt;"))
}
average_line&lt;-list(type="line",x0=others_average,x1=others_average,yref="paper",y0=0,y1=1,
                   line=list(color=blue,width=1,dash="dash"))
average_label&lt;-list(text="Average of the&lt;br&gt;other EU countries",x=others_average,xanchor="left",
                    y=1,yanchor="top",xref="x",yref="paper",showarrow=FALSE,
                    font=list(size=11,color=blue))
chart(p,paste0("Mean score in mathematics by family background, ",last),
      "learningtower (OECD PISA): quarters of each country by PISA's index of family background",
      annotations=list(average_label),legend=legend_top,margin=list(l=110,t=100,b=90),
      note_y=-0.08,y_axis=list(categoryorder="array",categoryarray=levels(background$label)),
      shapes=list(greece_band(levels(background$label)),average_line))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_PISA.html">Interactive chart: Mean score in mathematics by family background, 2022</a></p>
</div>
</div>
<p>But in Greece the students do not do well at either end. The least advantaged quarter scored 399, against 430 on average in the other EU countries, and the most advantaged 474, against 528: about the mean score of the other EU countries, 476.</p>
<hr>
</section>
<section id="what-does-pisa-2025-add" class="level2">
<h2 class="anchored" data-anchor-id="what-does-pisa-2025-add">7. What does PISA 2025 add?</h2>
<p>The OECD published the results of PISA 2025 on 8 September 2026; all 27 EU countries took part, among 91 countries and economies (European Commission 2026). Its student data are not yet in learningtower; what this page can show of it is the share of students below level 2, the basic level of PISA, which Eurostat already publishes for 2025.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16"><pre><code class="language-r"># the EU countries in the last round of Eurostat, and the place of Greece by its share of students
# below the basic level in mathematics: 1 is the highest share
low_eu&lt;-low[low$time==low_last&amp;low$subject=="math"&amp;low$geo%in%eu_countries$code,]
low_place&lt;-match("EL",low_eu$geo[order(-low_eu$values)])
rose&lt;-sapply(names(subjects),function(subject)
  low_value("EL",subject,low_last)&gt;low_value("EL",subject,low_before))</code></pre></div></div>
</details>
</div>
<p><strong>More Greek students below the basic level, in every subject.</strong> In 2025, 49.6% of Greek 15-year-olds were below level 2 in mathematics (47.2% in 2022), 43.9% in reading (37.6%) and 41.0% in science (37.3%). In the EU as a whole the shares were 33.9%, 31.3% and 25.9%. In mathematics, Greece had the 4th highest share of the 27 EU countries.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17"><pre><code class="language-r">rows&lt;-expand.grid(geo=c("EU27_2020","EL"),subject=rev(names(subjects)),stringsAsFactors=FALSE)
rows$before&lt;-mapply(low_value,rows$geo,rows$subject,low_before)
rows$after&lt;-mapply(low_value,rows$geo,rows$subject,low_last)
rows$label&lt;-paste0(subjects[rows$subject],", ",ifelse(rows$geo=="EL","Greece","EU-27"))
rows$label&lt;-factor(rows$label,levels=rows$label)
# the legend shows the two rounds in gray, as the rows are red for Greece and blue for the EU: its
# two markers are drawn under the first row's own, which hide them
p&lt;-plot_ly() %&gt;%
  add_trace(data=rows[1,],x=~before,y=~label,type="scatter",mode="markers",
            name=as.character(low_before),hoverinfo="none",
            marker=list(symbol="circle-open",size=10,color=dark_gray,line=list(width=2))) %&gt;%
  add_trace(data=rows[1,],x=~after,y=~label,type="scatter",mode="markers",
            name=as.character(low_last),hoverinfo="none",marker=list(size=10,color=dark_gray))
for(geo in c("EU27_2020","EL")) {
  x&lt;-rows[rows$geo==geo,]
  colour&lt;-if(geo=="EL") greek_red else blue
  p&lt;-add_segments(p,data=x,x=~before,xend=~after,y=~label,yend=~label,
                  line=list(color=colour,width=2),showlegend=FALSE,hoverinfo="none")
  p&lt;-add_trace(p,data=x,x=~before,y=~label,type="scatter",mode="markers",showlegend=FALSE,
               marker=list(symbol="circle-open",size=10,color=colour,line=list(width=2)),
               hovertemplate=paste0("%{y}, ",low_before,": %{x:.1f}%&lt;extra&gt;&lt;/extra&gt;"))
  p&lt;-add_trace(p,data=x,x=~after,y=~label,type="scatter",mode="markers",showlegend=FALSE,
               marker=list(size=10,color=colour),
               hovertemplate=paste0("%{y}, ",low_last,": %{x:.1f}%&lt;extra&gt;&lt;/extra&gt;"))
}
goal&lt;-list(type="line",x0=15,x1=15,yref="paper",y0=0,y1=1,
           line=list(color=dark_gray,width=1,dash="dash"))
goal_label&lt;-list(text="EU goal for 2030:&lt;br&gt;below 15%",x=15,xanchor="left",y=1,yanchor="top",
                 xref="x",yref="paper",showarrow=FALSE,font=list(size=11,color=dark_gray))
chart(p,paste0("15-year-olds below the basic level of PISA, ",low_before," and ",low_last,", %"),
      "Eurostat, sdg_04_40 (OECD PISA)",annotations=list(goal_label),legend=legend_top,
      margin=list(l=150,t=100,b=80),note_y=-0.2,
      x_axis=list(range=c(0,1.1*max(rows$after)),ticksuffix="%"),
      y_axis=list(categoryorder="array",categoryarray=levels(rows$label)),shapes=list(goal))</code></pre></div></div>
</details>
<div class="cell-output-display">
<p><a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_PISA.html">Interactive chart: 15-year-olds below the basic level of PISA, 2022 and 2025, %</a></p>
</div>
</div>
<p>The EU’s goal for 2030 is fewer than 15% below the basic level in each subject; the European Commission notes that the shares have risen sharply since 2015, especially in mathematics and reading, and that the EU continues to lag behind other advanced economies (European Commission 2026).</p>
<hr>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<ul>
<li>OECD, <a href="https://www.oecd.org/en/about/programmes/pisa/pisa-data.html">PISA data</a>: the student data of every round, prepared for R by Wang, K. and others (2026), <a href="https://kevinwang09.github.io/learningtower/">learningtower: OECD PISA Datasets from 2000–2022 in an Easy-to-Use Format</a>, R package version 2.0.0.</li>
<li>OECD (2023), <a href="https://doi.org/10.1787/53f23881-en"><em>PISA 2022 Results (Volume I): The State of Learning and Equity in Education</em></a>, OECD Publishing, Paris: the fall between 2018 and 2022, the year of learning, and the pandemic.</li>
<li>Results not compared over time: OECD (2013), <em>PISA 2012 Results</em>, country note for Austria (2009); OECD (2023), <a href="https://www.oecd.org/en/publications/pisa-2022-results-volume-i-and-ii-country-notes_ed6fbcc5-en/spain_f1a3afc1-en.html"><em>PISA 2022 Results</em>, country note for Spain</a> (2018); CPB Netherlands Bureau for Economic Policy Analysis, <a href="https://www.cpb.nl/sites/default/files/publicaties/download/cpb-achtergronddocument-onderwijsprestaties-nederland-perspectief.pdf">Onderwijsprestaties van Nederland in internationaal perspectief</a> (the Netherlands, 2000).</li>
<li>Eurostat: <a href="https://ec.europa.eu/eurostat/databrowser/view/sdg_04_40/default/table?lang=en">sdg_04_40</a> (low achieving 15-year-olds in reading, mathematics or science, from the OECD’s PISA).</li>
<li>European Commission (2026), <a href="https://education.ec.europa.eu/whats-new/news/1-in-3-eu-students-underachieve-in-reading-or-maths-amid-decline-in-basic-skills-and-teacher-shortages">1 in 3 EU students underachieve in reading or maths amid decline in basic skills and teacher shortages</a>, 5 October 2026.</li>
</ul>
<hr>
<p><em>Rendered with R 4.6.2 · plotly</em></p>
<!-- -->
</section>
<p>This post first appeared on <a href="https://sedzinfo.github.io/vignettes/illustration/ILLUSTRATION_PISA.html">Illustrations in R</a>, with its interactive charts and the full R code.</p>]]></content:encoded>
    </item>
  </channel>
</rss>
