gpt4 book ai didi

r - tmap R - 将主题图标题的字体从纯文本更改为斜体,但保持图例字体纯文本

转载 作者:行者123 更新时间:2023-12-04 13:43:35 25 4
gpt4 key购买 nike

我想使用 更改专题图主标题的字体 map 将 R 中的“普通”封装为斜体,但保留图例标题和文本“普通”的字体。

但是,当我更改 lm_layout() 函数中的参数 fontface 时,它​​会更改 map 中所有文本的字体。是否可以只更改 tmap 中主标题的字体?

我对可重现示例的尝试(不幸的是,将 map 中所有文本的字体更改为斜体)如下:

library(tmap)
data("World")

tm_shape(World) +
tm_polygons("HPI", title = "World - HPI") +
tm_layout(main.title = "HPI",
main.title.position = "center",
fontface = 3)

编辑:tmap 包的作者 Martijn Tennekes 已向 tm_layout(因此还有 tmap 选项)添加了 10 个参数以允许对此进行控制:( map )标题、主标题、panel.label 的本地字体和字体系列,图例.标题和图例.文本。
tm <- tm_shape(World) +
tm_polygons(c("HPI", "economy"), title = c("Legend 1", "Legend 2")) +
tm_layout(main.title = "Main Title",
main.title.position = "center",
title = c("Title 1", "Title 2"),
panel.labels = c("Panel 1", "Panel 2"))

# global setting
tm + tm_layout(fontface = 3)

# local setting
tm + tm_layout(main.title.fontface = 1, title.fontface = 2, panel.label.fontface = 3, legend.text.fontface = 4, legend.title.fontfamily = "serif")

最佳答案

已测试 tmap_2.1-1版本。

而图例标题在 tm_polygons可以通过 title = expression(italic(your-text)) 设置为斜体,情节标题似乎不允许 expression s。一种解决方法是使用 grid 的编辑功能。包裹:

library(tmap)
library(grid)

data("World")

tm_shape(World) +
tm_polygons("HPI", title = expression(italic(World - HPI))) + # set legend title to italic
tm_layout(main.title = "HPI", # unfortunately, does not allow `expression`; try the `grid` hack
main.title.position = "center")

# Convert to gTree/list of grobs
g <- grid.grab()
View(g) # check the structure of the gTree; helps with identifying graphical elements
# Edit the fontface of the main title - from 1 (plain text) to 3 (italic); must be integer
g[["children"]][[1]][["children"]][["main_title"]][["children"]][[1]][["gp"]][["font"]] <- 3L
# Draw the edited gTree
grid.newpage(); grid.draw(g)

enter image description here

关于r - tmap R - 将主题图标题的字体从纯文本更改为斜体,但保持图例字体纯文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53193908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com