Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【第四章 图库】如何在非图表处添加 caption 并交叉引用 #11

Closed
pzhaonet opened this issue Aug 16, 2019 · 4 comments
Closed
Labels
question Further information is requested

Comments

@pzhaonet
Copy link
Collaborator

原稿第 4.2 节“茎叶图”的图 4.3 和 4.4,本身的内容不是图,而是一段代码运行的结果。原稿里强行作为插图处理,添加了 caption 和 label,并在其他地方交叉引用。

这个功能在 bookdown 里如何实现?

@XiangyunHuang
Copy link
Owner

以 4.3 为例,

code2fig

这样转化处理即可

```{r stem-islands,fig.cap="(ref:stem-islands)",fig.scap="世界各地大陆块面积茎叶图"}
stem(islands)
stem(islands, width = 20)
# 可以增大窗宽stem(islands, scale = 2)看看效果
```

(ref:stem-islands) 本图展示了世界上主要的48块大陆面积的分布状况,可以明显看出,这些面积数据是严重右偏的,即:少数陆地块的面积非常大,而大多数陆地块的面积相对来说都很小。事实上,主要是七大洲的大陆块面积非常大,而其它岛屿诸如海南岛、帝汶岛、九洲岛等面积都相对较小。

得到的不是图片,极有可能这么些年下来 R 的函数发生变化,没想到内置的函数变化也这么大,我遇到的是 ggplot2 的变化,这个问题 @yihui 怎么看

@pzhaonet
Copy link
Collaborator Author

我就是这样处理的,但是不灵:

f69bc4e

ggplot2 确实变化很大,我在拿破仑远征图也遇到了。不过 stem 应该变化不大,返回的本来就是文本不是图,只不过书稿强行当图处理了。

@yihui
Copy link
Collaborator

yihui commented Aug 16, 2019

stem() 没有变化,如 @pzhaonet 所说,它本来就不是真正的图片,而是字符形式的“图”。在 LyX/LaTeX 里很容易把任意内容塞到 figure 环境中,在 R Markdown 中就没那么容易了……不行就别弄图了,就用字符形式的输出好了。

@pzhaonet
Copy link
Collaborator Author

好的。这样的话,就得把正文里对 stem 图交叉引用的文字进行修改,但是我希望迁移就只迁移,尽量一字不改。比如原文 "R 包超过了 2500 个"这样的话我都没改,只是加了个脚注。改的话再说改的事儿。

@XiangyunHuang XiangyunHuang added enhancement New feature or request good first issue Good for newcomers labels Aug 18, 2019
@XiangyunHuang XiangyunHuang changed the title 如何在非图表处添加 caption 并交叉引用 【第四章 图库】如何在非图表处添加 caption 并交叉引用 Aug 19, 2019
@XiangyunHuang XiangyunHuang added question Further information is requested and removed enhancement New feature or request good first issue Good for newcomers labels Aug 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants