XiangyunHuang / msg

:book: 现代统计图形(人民邮电出版社出版) Modern Statistical Graphics

Home Page:https://bookdown.org/xiangyun/msg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

【封面】 MSG 书籍封面

XiangyunHuang opened this issue · comments

参考这个思路 https://www.data-imaginist.com/art
我们也可以从某个统计、物理、数学、几何的方程出发,用 R 画个图做封面

commented

是的,我一开始的想法就是想用一个R画的图作封面,这样可以展示R在作图方面的优势。可惜我不太熟悉统计以及R。
还有一个思路是可以做一个word cloud 的标题,比如像这个一样的
https://cran.r-project.org/web/packages/wordcloud2/vignettes/wordcloud.html

我曾想过用这张图片,够复杂,够统计,就是有点太普通了,似乎画的人挺多,不够原创

cover.pdf
cover

绘图代码如下

# 代码修改自  http://www.ejwagenmakers.com/misc/Plotting_3d_in_R.pdf

library(tikzDevice)

# tikz('cover.tex', width=8.27, height=11.69, standAlone=TRUE)

tikz('cover.tex', width=8, height=6.5, standAlone=TRUE)

mu1 <- 0 # setting the expected value of x1
mu2 <- 0 # setting the expected value of x2
s11 <- 10 # setting the variance of x1
s12 <- 15 # setting the covariance between x1 and x2
s22 <- 10 # setting the variance of x2
rho <- 0.5 # setting the correlation coefficient between x1 and x2
x1 <- seq(-10, 10, length = 41) # generating the vector series x1
x2 <- x1 # copying x1 to x2
f <- function(x1, x2) {
  term1 <- 1 / (2 * pi * sqrt(s11 * s22 * (1 - rho^2)))
  term2 <- -1 / (2 * (1 - rho^2))
  term3 <- (x1 - mu1)^2 / s11
  term4 <- (x2 - mu2)^2 / s22
  term5 <- -2 * rho * ((x1 - mu1) * (x2 - mu2)) / (sqrt(s11) * sqrt(s22))
  term1 * exp(term2 * (term3 + term4 - term5))
} # setting up the function of the multivariate normal density
z <- outer(x1, x2, f) # calculating the density values
nrz <- nrow(z)
ncz <- ncol(z)
nbcol <- 100
color <- hcl.colors(100)
# Compute the z-value at the facet centres
zfacet <- z[-1, -1] + z[-1, -ncz] + z[-nrz, -1] + z[-nrz, -ncz]
# Recode facet z-values into color indices
facetcol <- cut(zfacet, nbcol)
par(mar = c(4.1, 4.1, 4.5, 1.5))
persp(x1, x2, z,
      xlab = "$x_{1}$",
      ylab = "$x_{2}$",
      zlab = "$f(x_{1},x_{2})$",
      main = "Two dimensional Normal Distribution",
      col = color[facetcol], border = NA, theta = 30, phi = 20,
      r = 50, d = 0.1, expand = 0.5, ltheta = 90, lphi = 180,
      shade = 0.1, ticktype = "detailed", nticks = 5, box = TRUE
)
mtext("$\\mu_1 = 0,\\mu_2 = 0,\\sigma_{11} = 10,\\sigma_{22} = 10,\\sigma_{12} = 15, \\rho = 0.5$", side = 3)
mtext("$f(x_{1},x_{2}) = \\frac{1}{2\\pi\\sqrt{\\sigma_{11}\\sigma_{22}(1-\\rho^2)}}\\exp\\big\\{-\\frac{1}{2(1-\\rho^2)}[\\frac{(x_1 - \\mu_1)^2}{\\sigma_{11}} - 2\\rho\\frac{(x_1 - \\mu_1)(x_2 - \\mu_2)}{\\sqrt{\\sigma_{11}}\\sqrt{\\sigma_{22}}} + \\frac{(x_2 - \\mu_2)^2}{\\sigma_{22}}]\\big\\}$",
      side = 1, line = 2
)

dev.off()

tinytex::xelatex('cover.tex')

运行环境

sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936  LC_CTYPE=Chinese (Simplified)_China.936   
[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C                              
[5] LC_TIME=Chinese (Simplified)_China.936    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tikzDevice_0.12.3

loaded via a namespace (and not attached):
[1] compiler_3.6.1 tools_3.6.1    tinytex_0.16   filehash_2.4-2 grid_3.6.1     xfun_0.9 

PDF 格式图片转 PNG 格式

convert -quality 100 -antialias -density 300 -transparent white -trim cover.pdf cover.png

最缺的不是 R 语言画图,而是对统计的理解,有一个好的 idea 最重要,剩下的只是技术细节,有谢大这个首席顾问在,技术什么的都是浮云!我先提供一个思路,图要来自非常有意思的一个真实数据案例,这个案例自然也放在书的正文中,足够吸引眼球,图本身就是一个故事,最好能引发思考!

附件是一个数据集,收集自书籍 Leading Personalities in Statistical Sciences_ From the Seventeenth Century to the Present (1997),记录了17世纪到20世纪最伟大的115位统计学家的信息,许宝騄是唯一一个华人,他的名言是

我不希望自己的文章登在有名的杂志上因而出了名;我希望一本杂志因为刊登了我的文章而出了名。

数据集四个字段的含义如下

  • name: 统计学家的名字
  • birth: 出生日期
  • death: 死亡日期
  • age: 年龄

大家对这个数据集有没有什么想法? @yihui @pzhaonet

statisticians.zip