Forum Discussion
R background image error
- 8 years ago
I finally got this working with help from @boefraty.
I encoded the image as base64 (here for example: https://www.base64-image.de), then read it into my rscript, decoded, and used it as a raster. I am still looking for a more elegent solution for diplaying points on an interior space. Below is the code.
library(jpeg)
library(ggplot2)
library(base64enc)
b64img2<-"encoded string here"
rawimg<-base64decode(b64img2) img<-readJPEG(rawimg) rast<-grid::rasterGrob(img,interpolate=T) ggplot(dataset,aes(Longitude,Latitude))+annotation_custom(rast,xmin=-85,xmax=-84,ymin=45,ymax=46)+geom_point(aes(color=factor(DeviceName)),shape=1,show.legend=FALSE)+xlim(-85,-84)+ylim(45,46)+theme(panel.background=element_blank(),panel.border=element_blank(),axis.text.x = element_blank(), axis.text.y = element_blank(), axis.ticks = element_blank(),axis.title.y=element_blank(),axis.title.x=element_blank())
petermcnally Pretty certain that if it isn't on the list, it won't work. Can you swap out for GridBase or GridExtra, those appear to be supported.
That would be pretty strange that gridBase and gridExtra would work, but grid doesn't. As you can see in the attached, grid is a required package for gridBase. Again, grid is installed by Power BI in the library when installing R from PowerBI desktop.
- petermcnally8 years agoAdvocate IV
I finally got this working with help from @boefraty.
I encoded the image as base64 (here for example: https://www.base64-image.de), then read it into my rscript, decoded, and used it as a raster. I am still looking for a more elegent solution for diplaying points on an interior space. Below is the code.
library(jpeg)
library(ggplot2)
library(base64enc)
b64img2<-"encoded string here"
rawimg<-base64decode(b64img2) img<-readJPEG(rawimg) rast<-grid::rasterGrob(img,interpolate=T) ggplot(dataset,aes(Longitude,Latitude))+annotation_custom(rast,xmin=-85,xmax=-84,ymin=45,ymax=46)+geom_point(aes(color=factor(DeviceName)),shape=1,show.legend=FALSE)+xlim(-85,-84)+ylim(45,46)+theme(panel.background=element_blank(),panel.border=element_blank(),axis.text.x = element_blank(), axis.text.y = element_blank(), axis.ticks = element_blank(),axis.title.y=element_blank(),axis.title.x=element_blank())