I am trying to put a pin with information in a position on a static image by using R. Does someone have any suggestion how to do this?
Thanks in advance
code
#load libraries
library(ggplot2)
library(plotly)
library(png)
library(grid)
library(ggthemes)
library(gridExtra)
#create an example dataframe
df<-data.frame(column1=c('A','B','C'),
column2=c(50,40,50))
#create an gggplot object
plot<-ggplot(df,aes(x=column1,y=column2,fill=column2))+
geom_bar(stat="identity",width=1)+
theme(panel.background=element_blank(),
panel.border=element_blank(),
panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
plot.background=element_blank(),
legend.position = 'none')
plot_list<- list(plot,plot,plot)
#put it on a image
plot_list_test<- function(plot_list){
ima<- readPNG("testeimage.png")
png("rplot.png", width = 4500, height = 2500, units = "px")
plot.new()
lim <- par()
rasterImage(ima, lim$usr[1],lim$usr[3] ,lim$usr[2] , lim$usr[4])
vp <- viewport(.2, 0.55,width =.04, height = .12) #onde quer que fique
pl <- plot_list[1]
print(pl, vp = vp)
pl2 <- plot_list[2]
vp2 <- viewport(.53, 0.87, width =.04, height = .12)
print(pl2, vp = vp2)
pl5 <- plot_list[3]
vp5 <- viewport(.5, 0.78,width =.04, height = .12)
print(pl5, vp = vp5)
dev.off()
}
plot_list_test(plot_list)
##[Alternative]plottly to make it interactive to see value in the plots, but i can not plot them on the static image.
ggplotly(plot)
#image