0

I'm fairly new to R, so I may be missing something obvious...but so far my Google-fu has utterly failed me and my attempt to solve this problem has resulted in the coding equivalent of printing something out, sending a fax, and then drawing a picture from the fax.

So, for example, if the plot was a picture of a smiley face (that's not my plot, but I was trying to have fun with it while pulling my hair out. I was hoping to have something that works off of the image created by R but is fairly image agnostic) then I'm trying to return something like this...either in a single string or one for each row. (it could be any characters reflecting on and off, I was assuming binary would be the easiest)

000000000000000000000000000
000000000000000000000000000
000000000000000000000000000
000001100001100000000000000
000001100001100000000000000
000000000000000000000000000
000000000000000000000000000
000000000000000000000000000
000000000000000000000000000
000000000000000000000000000
000110000000001100000000000
000011000000011000000000000
000001111111110000000000000
000000000000000000000000000
000000000000000000000000000
000000000000000000000000000
000000000000000000000000000

That's the general idea, and so far my only near success has involved printing to disk and then re-reading it...which I'm 100% sure is a bad approach. I'm good with SQL and formulas, but R is a whole new world for me.

The reasoning behind this is that I'm delivering the information to a box that only can handle text and is designed to receive a string, but I can shrink the text down to a font size of '2'and essentially create a grid of pixels. I've already added some semi-graphical text (bar charts with a repeat function, waffle charts with a bit more effort, that sort of thing)...and this is just me following the logical progression (and also, hopefully, saving a LOT of screen real estate)

I'm suspecting this is a lot easier than I'm making it, as it's essentially the step R goes through in the process of making a plot...but I've clearly failed.

Any help would be hugely appreciated!

  • Can you give us some more information and some toy data to play with? You will be much more likely to get help and an answer! For example, what format is the R 'plot' that you mention as being the source data? Do you mean an image or picture or an actual plot as created with `plot()`? Without knowing more, I would think that using the `raster` package might give you the tools you need, but that is just a guess. Also, see [this](http://stackoverflow.com/q/5963269/3897439) post for advice on how to ask a good reproducible R question. – Cotton.Rockwood Nov 02 '16 at 22:18
  • Thanks, that's definitely something I should clarify. By plot I was thinking 'graph created by R', I was hoping to come up with something fairly image agnostic...so a plot, histogram, polygon, or scatterplot ...that sort of thing. So, literally 'the pixels that make up the image converted to a string, replaced by 0s and 1s (or xs and os, or spaces and xs...anything that represents an on and off bit in a black and white image) (Also editing the original to clarify, thanks!) – William Holz Nov 02 '16 at 22:56
  • I think you will have trouble finding a solution that works for any object, but I may be wrong. In the case of vector graphics, for example, there are no pixels. However, one solution might be to use a graphics device to output an image in a 0/1 format? [This](http://stackoverflow.com/a/3502527/3897439) post actually provides the binary form of a plot image... maybe you could convert the binary to 0/1? – Cotton.Rockwood Nov 02 '16 at 23:10
  • See, you're demonstrating how little I know about R. I'm going to have to start helping people on the SQL side so that I feel less oblivious. ;) And yeah, that's a really good point, I didn't know that R didn't do a conversion to pixels when it displayed an image. I kind of figured out the 'print to a file, then read the file with one of the libraries' bit (or at least I figured it has to work), it just felt really dirty to take that approach. You think that's all we'd have? And yeah, that link's a bit cleaner than my approach. Getting used to R's context is hard! – William Holz Nov 03 '16 at 01:21

1 Answers1

0

I think that using gridGraphics package as in this thread, you might be able to achieve just that.

maybe some other libraries allow you to access the parameters of the plot as well...

Community
  • 1
  • 1
ira
  • 2,542
  • 2
  • 22
  • 36