knitr::opts_chunk$set( collapse = TRUE, comment = "#", fig.path = "man/Figure/", dev = 'svg', out.width = "100%" )
lattice.layers
确实可以做出一些炫酷的图,但维护着实不易。
install.packages("lattice.layers")
library(lattice.layers) library(Ipaper) # install_githubrpkgs/Ipaper library(sp)
sp_plot
两种绘图语法:
sp::spplot
的绘图方法;lattice::levelplot
的绘图方法。formula的书写方式与
lattice::levelplot
的语法格式一致,只是这里的横轴和纵轴坐标是固定lon+lat
。以formula = slope ~ lon + lat | type
为例:~
前的变量slope是绘图变量z值,|
之后的变量type表示group。
sp_plot
提供了给显著性的格点打patch的功能。需要df
中含有mask变量,TRUE表示显著。
grid2 = grid_slope df = grid2@data %>% mutate(mask = pvalue <= 0.05) df = list(a = df, b = df %>% mutate(slope = slope + 0.1)) %>% melt_list("type") p <- sp_plot(grid2, df, df.mask = df[, .(type, mask)], formula = slope ~ lon + lat | type, ylim = c(-60, 95), xlim = c(-180, 180) + c(-1, 1)*10, layout = c(2, 1), colorkey = list(space = "bottom"), density = 0.1) + theme_lattice( key.margin = c(1, 1, 1, 1), plot.margin = c(0, 1, 2, 1)) p # write_fig(p, "a.pdf", 7, 6)
# add layers lyrs = layers( layer_signDist(density = 0.1, lwd = 0.2), layer_signPerc(x = 0.01, y = 0.72, fill = "white"), layer_barchart(y = 0.12)) p + lyrs
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.