春秋时期的天文:日食
日升月落,星移斗转,是最鲜明的天体运动。先民在长期观察中,发现气候寒温、草木荣枯与天象之间存在紧密的关系。上古时期,历法还不够成熟,而且也不够普及;又没有准确的计时系统。天象在先民的日常生活中起着极其重要的作用。这就是为什么“三代以上,人人皆知天文”的缘故。到了后世,历法发达,计时系统逐渐准确,而大部分人又不必从事与气候紧密相关的农业劳动,因此,“有问之文人学士而懵然不知者”。
2020-08-17
6 min read
How to define aesthetic mappings of ggplot2 within another function
ggplot2 is great for visualization, but sometimes we need to include ggplot2 functions within another function. ggplot() uses aes() to define aesthetic mappings of different variables. The question is: how to define aesthetic mappings when writing functions using ggplot()? In this post I will present several approaches. First of all, let’s load the required packages and some test data. library(ggplot2) library(dplyr) data("mtcars") Using aes_string() There are two standard ways to define aesthetic mappings in ggplot2, aes_string() and aes_(). Writing a function using aes_string() is the same as using aes(), but calling the function requires passing the variable names as strings to the function.
2020-03-28
1 min read
Writing Praat scripts in a modular way
Praat is widely used in phonetic research. Working with Praat involves inevitably the Praat scripting. There are plenty of resources of Praat scripts as well as great tutorials to Praat scripting (see below). Why bother writing Praat scripts oneself? Praat scripts written by others can be helpful, but even an script is available which offer the functionality one needs, it is seldom exactly what one wants. It is normal to do some tailoring to the scripts. Users of Praat may be great phoneticians, but rarely are they professional programmers. When I write my own Praat scripts, I try to explicitly adopt some principles and conventions to facilitate the reusability of code. This post is about these principles and conventions.
2019-12-06
3 min read