在Jupyter中显示R中的ggplot2图 [英] Displaying ggplot2 graphs from R in Jupyter
问题描述
当我使用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图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!