R ggplot2:栅格grob的annotation_custom不绘制 [英] R ggplot2: annotation_custom of raster grob does not plot

查看:357
本文介绍了R ggplot2:栅格grob的annotation_custom不绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新
原来是无法通过远程桌面连接产生光栅图形的问题。 / p>

我想将文件中的图像插入到使用ggplot2创建的图中。这个问题已经在这里提出(插入图片到ggplot2 ),但对我来说,接受的答案会产生一个没有任何图像的情节。没有错误或警告:坐标轴,网格和点都绘制得很好,但没有R标志(已导出情节;我无法在此上传图片)。代码如下:

 库(ggplot2)
库(png)
库(网格)

img < - readPNG(system.file(img,Rlogo.png,package =png))
g < - rasterGrob(img,interpolate = TRUE)

qplot(1:10,1:10,geom =blank)+
annotation_custom(g,xmin = -Inf,xmax = Inf,ymin = -Inf,ymax = Inf)+
geom_point()

我尝试过使用xy值并使用了几个不同的值图像和格式,但无济于事。



我遇到的问题特定于使用带有annotate_custom()的rastergrob对象,如 annotate_custom()的ggplot2文档网站工作得很好,例如:

  library(gridExtra)

qplot(1:10,1:10,geom =blank)+
annotation_custom(grob = tableGrob(head(iris [,1:3])),
xmin = 3,xmax = 6,ymin = 2,y最大= 8)

我在windows上使用64位R版本3.0.2与ggplot2版本0.9.3.1和我的软件包全部更新。



任何想法都会受到欢迎,如果我错过了一些简单的事情,我们深表歉意!

解决方案

正如对这个问题的答案( R基包网格不会产生输出),R不会在远程桌面连接上在窗口设备中正确生成栅格图像。



我正在使用远程桌面连接访问R,因此栅格grob不会绘图。如果需要栅格图像,则必须将绘图输出到其他设备。

UPDATE Turns out it was an issue of not being able to produce raster graphics over a remote desktop connection.

I want to insert an image from file into a plot made with ggplot2. This question has already been asked here (Inserting an image to ggplot2) but for me the accepted answer produces a plot devoid of any image. There are no errors or warnings: the axes, grid, and points all plot just fine but there's no R logo (exported plot; I couldn't upload an image here). Code below:

library(ggplot2)
library(png)
library(grid)

img <- readPNG(system.file("img", "Rlogo.png", package="png"))
g <- rasterGrob(img, interpolate=TRUE)

qplot(1:10, 1:10, geom="blank") +
  annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
  geom_point()

I've tried playing around with the xy values and have used several different images and formats but to no avail.

The problem I'm having is specific to using a rastergrob object with annotate_custom(), as the examples given on the ggplot2 documentation site for annotate_custom() work just fine, e.g.:

library(gridExtra)

qplot(1:10, 1:10, geom = "blank") + 
  annotation_custom(grob = tableGrob(head(iris[ ,1:3])),
  xmin = 3, xmax = 6, ymin = 2, ymax = 8)

I'm using 64-bit R version 3.0.2 on windows with ggplot2 version 0.9.3.1 and my packages are all updated.

Any thoughts would be most welcome, and apologies if I'm missing something simple!

解决方案

As explained in an answer to this question (R base package grid does not produce output), "R does not produce raster images correctly in the window device over Remote Desktop Connection. If a raster image is required, the plot must be output to another device."

I was accessing R using a Remote Desktop Connection and thus the raster grob would not plot.

这篇关于R ggplot2:栅格grob的annotation_custom不绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆