我正在尝试制作一本书,其中包含以下代码
ggdotchart(themes, x = "theme", y = "citations", # requires `easyGgplot2`, `ggplot2`, `ggpubr`
color = "#440154", # Color by groups
palette = c("#00AFBB", "#E7B800", "#FC4E07"), # Custom color palette
sorting = "descending", # Sort value in descending order
add = "segments", # Add segments from y = 0 to dots
rotate = TRUE, # Rotate vertically
dot.size = 9, # Large dot size
label = round(themes$citations), # Add citations values as dot labels
font.label = list(color = "white", size = 10,
vjust = 0.5), # Adjust label parameters
ggtheme = theme_pubr(), # ggplot2 theme
ylab="Citation Count",
xlab="Theme"
)
当我在控制台中运行代码时,我得到以下图形:
但是当我编织时我得到这个错误:
Quitting from lines 28-42 (bookdown-demo.Rmd)
Error in ggdotchart(themes, x = "theme", y = "citations", color = "#440154", :
could not find function "ggdotchart"
Calls: <Anonymous> ... withVisible -> eval_with_user_handlers -> eval -> eval
In addition: Warning message:
In xfun::prose_index(x) : Code fences are not balanced
Execution halted
或者当我构建时,出现以下错误:
Quitting from lines 54-68 (bookdown-demo.Rmd)
Error in ggdotchart(themes, x = "theme", y = "citations", color = "#440154", :
object 'themes' not found
Calls: local ... eval_with_user_handlers -> eval -> eval -> ggdotchart
Execution halted
Error: bookdown::render_book() failed to render the output format 'bookdown::gitbook'.
Execution halted
Exited with status 1.
我试过
themes$citations <- as.character(themes$citations)
和
load("themes.RData")
我正在使用 Bookdown 模板 repo 的新副本。 我的仓库在这里。
请让我知道我是否应该在此处添加任何其他上下文。
科林
感谢@stefan 让我在这方面走上正轨。
这里是关键点,对于那些刚开始使用 rMarkdown 和 bookdown 的人来说,这显然是一个常见的问题。
library(package)
或 require(package)
readr
,或tidyverse
dataframe <- read_csv("path/to/file.csv")
将您需要的数据加载到一个名为 dataframe 的对象(或任何适合您喜欢的对象)中。这将在您的 .Rmd.knitr::opts_chunk$set(echo = FALSE)
require(ggplot2)
require(easyGgplot2)
require(ggpubr)
require(readr)
pubdate <- read_csv("data/pubdate.csv")
themes <- read_csv("data/themes.csv")
我很可能遗漏了一些细微差别,或者有更简约的解决方案,我很高兴收到你的来信。