so i'm trying to display an R generated image while using wxpython and rpy2...
The full 131 line code is here... https://gist.github.com/ACollectionOfAtoms/4286c0fc32838b03f2ea
So within the program, the user comes to a point where they are a window genereated by lst_view, which has two buttons "Ok" and "Visualize". Once Visualize is pressed this code is executed..
def graph(self,event):
f = open('results.csv', 'wb')
csvwriter = csv.writer(f)
for i in self.res:
for j in range(1,len(i)):
row = [i[0] ,str(i[j])]
csvwriter.writerow(row)
f.close()
r = robjects.r
r('''
source('vis.r')
''')
r_main = robjects.globalenv['main']
r_main()
return True
Where in vis.r we have:
graph <- function() {
res = read.csv("results.csv", header=FALSE)
res = mutate(res, Percent = 100*(V2/(sum(res$V2))))
ggplot(data=res, aes(x=V1, y=V2, fill=Percent)) + geom_bar(stat="identity") + coord_flip() + xlab('Facility') + ylab('Number Of Violations')
}
main <- function(){
print(graph())
}
This doesn't immediately generate the graph, instead it causes a new menu to appear and the graphic only displays if I go to "Page Setup"....
Anyone ideas?!
Alright, thanks to unutbu I was able to figure this out!
Basically I initially wanted to save the image and then visualize it with wx, but i had problems using dev.off() and such through rpy2!
BUT! unutbu provided a link and saved me a ton of trouble. you can use ggsave() to completely circumvent the whole jpeg('this.jpg'); dev.off(); business!
Thanks again, unutbu. Now i'll just render it with wx no problem!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.