Подтвердить что ты не робот

Ggplot2 footnote

Каков наилучший способ добавить сноску в конец графика, созданного с помощью ggplot2? Я попытался использовать комбинацию отмеченной здесь логики, а также функцию annotate ggplot2.

p + annotate("text",label="Footnote",
  x=unit(1,"npc") - unit(2, "mm"),y=unit(2, "mm"),
  just=c("right", "bottom"),gp=gpar(cex= 0.7, col=grey(.5)))

но я получаю ошибку

Ошибка в as.data.frame.default(x [[i]], необязательно = TRUE, stringsAsFactors = stringsAsFactors): невозможно преобразовать класс c ("unit.arithmetic", "unit") в data.frame

4b9b3361

Ответ 1

Я бы использовал что-то вроде этого:

pdf("filename.pdf", width=10, height=6) # open an appropriate graphics device
print(p)
makeFootnote() # from webpage above (uses grid.text; ggplot2 is based on grid)
dev.off()

Ответ 2

labs(caption = "my caption") добавляет сноску:

ggplot(mtcars, aes(mpg, wt, colour = cyl)) + 
  geom_point() + 
  labs(caption = "(Pauloo, et al. 2017)")

enter image description here