Create Editable plots from R - graphics

I'm creating a series of plots in R (I'm using ggplot2, but that's not essential) and I want to be able to save my output so I can then edit it for furthur use, For instance, I might want to move legends about, or adjust colours etc. I have seen that ggplot2 has a save command but that seems to produce pdf's or bitmaps, neither of which are particularly editable
How do other people do this ? Any good ideas ?
Here's some sample code to produce a sample plot;
library(ggplot2)
dataframe<-data.frame(fac=factor(c(1:4)),data1=rnorm(400,100,sd=15))
dataframe$data2<-dataframe$data1*c(0.25,0.5,0.75,1)
dataframe
testplot<-qplot(x=fac, y=data2,data=dataframe, colour=fac, geom=c("boxplot", "jitter"))
testplot
Thanks
Paul.

Other editable formats:
Take a look at help(devices) for other formats which are available: these include svg, pictex and xfig, all of which are editable to greater or lesser extents.
Note that PDFs can be edited, for instance using the Omnigraffle tool available for Apple's OSX.
Other ways to record plot data:
In addition, you can record R's commands to the graphics subsystem for repeating it later - take a look at dev.copy:
Most devices (including all screen devices) have a display list
which records all of the graphics operations that occur in the
device. 'dev.copy' copies graphics contents by copying the display
list from one device to another device. Also, automatic redrawing
of graphics contents following the resizing of a device depends on
the contents of the display list.
Using Rscript to create a repeatable, editable plot:
I typically take a third strategy, which is to copy my R session into an Rscript file, which I can run repeatedly and tweak the plotting commands until it does what I want:
#!/usr/bin/Rscript
x = 1:10
pdf("myplot.pdf", height=0, width=0, paper="a4")
plot(x)
dev.off();

With ggplot and lattice, you can use save to save the plot object to disk and then load it later and modify it. For example:
save(testplot, file = "test-plot.rdata")
# Time passes and you start a new R session
load("test-plot.rdata")
testplot + opts(legend.position = "none")
testplot + geom_point()

Thanks for the answers, I've played around with this, and after some help from my friend Google I found the Cairo package, which allows creation of svg files, I can then edit these in Inkscape.
library(Cairo)
Cairo(600,600,file="testplot.svg",type="svg",bg="transparent",pointsize=8, units="px",dpi=400)
testplot
dev.off()
Cairo(1200,1200,file="testplot12200.png",type="png",bg="transparent",pointsize=12, units="px",dpi=200)
testplot
dev.off()
Now I just have to play around with the various settings to get my plot as good as it can be before writing the file.

right click the mouse on the output plot
Copy as metafile
then save plot into a word document (right click to edit picture to covert to the plot to Microsoft Office drawing Object)

Related

pyqtgraph histogram find and set colour automatically

I have a pyqtgraph imageitem with an associated histogram. I can change the colour of the image by selecting it from the histogram. What I want to do is save the name/number/something of this process so that I can later create the image and automatically load this colourmap using just this information.
How do I do this?
I can see the values of the colourmap in LUT but saving 512 x 3 values is a bit too much for me. I would really appreciate a better solution.
I found an alternative way to do this. When I click on the colourmap I record the selection in the program and can then use this whenever I want.

Zero-sized print margins in Excel

Lets assume that for some reason I want to draw a beautiful orange rectangle that fills the whole page without margins. I set up my page like this:
img
set all my margins to 0:
img
and obviously get this beautiful picture in Ctrl+P menu: img
Unless I launch this file on some other machine that only lets me do something like this: img (that's not exactly the image from the other machine, but it looks like this).
See those white margins? I can't get rid of them. Excel tells me that all margins are set to 0 and I can't change rows/columns size to remove those white lines.
I would much appreciate any help on this matter. Excel version are the same. The only difference I can think of - I have no printer drivers (because I have no printer) and the other machine has some printers installed. Can the problem be with printer drivers? I checked their options and didn't find anything related to margins.
Try Using Page Size exactly as your output page. May be you are using Letter Page size in Excel but having physically A4 size.
Looks like the problem was with printer after all. Changing printer fixed the issue.

How do I vary stroke on a line to create an effect similar to "Ed, Edd, and Eddy"?

I'm trying to create the "Ed, Edd, and Eddy" art style. Here's an example image:
Specifically, I'm trying to capture the effect of having accent lines with varying stroke values within the same line.
I have access to the Adobe suite. Spent a couple hours trying to see if I could do something in Photoshop or Illustrator to no avail. Any help?
You'll need to use Illustrator, here's a quick tutorial on how it's done in Illustrator CC.
Draw your starting shape:
Choose the width tool from the toolbox
click anywhere on the path and drag it out to the desired width
Repeat this (you can widen and thin the stroke) until you have the desired result.
In Photoshop, simply create a brush that is pressure sensitive (= change brush diameter with pressure) with your tablet.
That should give you the desired effect.
#user3488148 you are looking for a free form drawing strokes and for that you can use a brush that provides accents while you draw and can respond to pressure (if a tablet stylus is used) as well. Check out for inbuilt brushes and modify their diameter, length, pressure, etc.

How to read a map into octave

This is a follow up to my post three weeks ago here How do I use m_map in octave, without really being a nuissance to kind and busy people. My problem is simply how does one overlay a basemap on an octave contour plot. After interpolating my irregularly spaced data (works for both contour lines and filled contours) I plot with the code:
contour(xi, yi, obsi, cstart:cstep:cend)
colorbar;
xlabel('Longitude'),ylabel('Latitude')
title('Mean Rain Onset')
saveas(gcf,'rainzam.pdf')
And I get
I have downloaded several map formats: ne_50m_admin_0_countries.zip, the apparently obsolete m_map (with associated tbase.Z, gshhg-bin-2.3.2.zip), soa.7z, world-bounds.7z, gshhg-gmt-2.3.2.tar.gz, dcw-gmt-1.1.1.tar.gz.
My question is has anyone used any of these maps in octave or gnuplot, and how to? I would appreciate any assistance.
Basically you have to load those maps in octave, they represent borders or coastlines with two variables (x,y) which you can then add to your plot with
hold on
plot(x,y)
That's the easy part, the hard part is to load the maps. All of them have different formats, which means it is a completely different story how to load them. For instance, the ne_50m_admin_0_countries.zip has a dbf format. Either you convert it first to ascii text and load it easily with the load function of octave or you need the OI package (http://wiki.octave.org/IO_package), which in turn demands java (http://wiki.octave.org/Java_package). I don't think this is the easy way for a newbie, so I suggest to convert the maps individually to text: google for "convert dbf to csv", "convert dbf to text", "convert dbf to ascii", etc... Perhaps some of those maps can be even loaded with excel and then saved as text (csv), the important issue is to convert them to text!
If you want to draw physical coastlines, you may download them from this link
https://www.naturalearthdata.com/downloads/
Then, after the drawing of a contour map of your own datas, you may add the coastlines using the following commands:
pkg load mapping
hold on
h = shapedraw ('FileName.shp','r','linewidth',1)

How can I convert several .ai files to various sized .png files automatically?

I am making a deck of cards in Adobe Illustrator. Each card is saved as it's own .ai file so I can change it later if I want to. When using these images in an iOS app, I must convert everything to .png files. Then I must re-size those .png files to have retina and non retina versions. I'm hoping there is a way that will allow me to automatically take a folder of all my .ai files and give .pngs of 200px x 400px and 100 x 200px. Also I'd like the larger ones to automatically be named #2xNameOfOrginalFile.png and the others to be named nameOfOrginalFile.png. I see stuff about batch automated scripting that does stuff like that. I'm curious how simple that is to implement. Is what I'm suggesting possible? Is this an easy process?
Seems pretty easy to do. Someone has posted a script that will do what you want: http://forums.adobe.com/message/4915819
You'll have to change these lines,
pngExportOpts.horizontalScale = 250.0;
pngExportOpts.verticalScale = 250.0;
to calculated values. The scale is a percentage (see: the docs). You can use sourceDoc.width and sourceDoc.height to get the width and height of the original .ai file (in pixels? docs don't say).
You'll also want to modify the getNewName function.

Resources