问题描述
当我使用 ggplot2
R 包在 Jupyter 中创建绘图时,我得到一个指向图表的链接,上面写着查看 PDF",而不是内嵌显示的图表.
When I create a plot in Jupyter using the ggplot2
R package, I get a link to the chart that says "View PDF" instead of the chart being presented inline.
我知道,传统上在 IPython Notebook 中,您可以使用 %matplotlib
魔术函数内联显示图表.Jupyter 对 R 和 ggplot2 有类似的东西吗?
I know that traditionally in IPython Notebook you were able to show the charts inline using the %matplotlib
magic function. Does Jupyter have something similar for R and ggplot2?
我需要做什么来内联显示图形而不是显示为 PDF 的链接?
What do I need to do to show the graph inline versus as a link to a PDF?
推荐答案
您可以使用此选项内联显示图表.
You can show the graphs inline with this option.
options(jupyter.plot_mimetypes = 'image/png')
您还可以像在 R 中一样生成 pdf 文件,例如
You can also produce pdf files as you would regularly in R, e.g.
pdf("test.pdf")
ggplot(data.frame(a=rnorm(100,1,10)),aes(a))+geom_histogram()
dev.off()
这篇关于在 Jupyter 中显示来自 R 的 ggplot2 图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!