Change background color of tkplot (igraph,R) - r

I currently have a network plotted with tkplot(). Originally, I was saving these plots as pngs, but they were too compressed and I liked how a screen shot of the tkplot looked. Is there anyway to make the background of the plot white? Instead of the light grey.

A couple points to clarify things.
If the PNG was too crowded, you can create a bigger PNG file, just specify width and height in the png() call. Or you can make the vertices smaller as well.
The purpose of tkplot() is that sometimes it is just easier to hand-adjust vertex coordinates. The idea is that you call tkplot(), adjust the coordinates, query the adjusted coordinates via tkplot.getcoords(), and then use them with plot(), because plot() is just much more flexible than tkplot().
It is actually possible to change the background color in tkplot(), here is how:
library(igraph)
g <- graph.ring(10)
id <- tkplot(g)
tkconfigure(igraph:::.tkplot.get(id)$canvas, "bg"="lightyellow")
In the next version of igraph it will be possible to query the canvas via tkplot.canvas(), so you won't need to use the internal igraph:::.tkplot.get() command for this.
Unfortunately the background color of the canvas is a property of the widget, so when you export the canvas to EPS, it will be ignored. The way to get around this requieres that you plot a big rectangle of the desired color, and place it below the vertices and edges in the canvas. This is definitely possible, but it is just easier to query the coordinates via tkplot.getcoords() and then use plot().

There is no color in the background of tkplot-produced objects. It is designed to output eps-postscript files which are basicall transparent and designed to be overlayed on some other file. Open the output of an exported file in a reader and you will see no color in the background. Here's what you get when your run the example on the tkplot page, save as an eps file and open with Preview.app on a Mac. (You should be able to use Ghostscript or ImageMagick for similar display.)

Related

rectangles on Grace plots

I have been using Grace (xmgrace) plotting for many years. I recently had an important idea for my work, and it involves rectangles on my plots. Grace supports rectangles (called "boxes"), but when I use a filled "box" it blocks my data curves. I want the curves to show over the filled rectangles. This is driving me nuts. Does anyone know how to put the filled rectangles in the background so they don't block data curves? Thanks.
Unfortunately there is no option in the xmgrace graphical interface that allows you to modify the z order of drawing objects such as boxes:
I also saved the graph as an .agr file and viewed it in a text editor. There doesn't seem to be any flag within the file format to modify z position, either.
Same story if you save a parameter file and check it in a text editor.
So it looks like it is really not possible in xmgrace.
One workaround would be to print to a postscript, EPS or SVG file and open it inside a vector graphics program such as Inkscape (results vary, you might need to experiment with filetypes to see which works best). Then you can easily alter the z order of objects.

Change edge thickness with tkplot (Igraph, R)

I was wondering if there is a way to change the edge thickness when using tkplot()
I know you can do it by right clicking the edge and changing it manually, but I would like to be able to call up an attribute to use for the edge. Similar to when using the normal plot function in igraph where I can do edge.width=E(g)$Weight
Also, is there a way to save the tkplot as a png without the use of other packages?
Thanks!
Yes, you can change the edge width, actually it works exactly the same way as for plot().
The Tk canvas does not support the PNG format, so you cannot save tkplot() output in PNG. If you use tkplot() for adjusting coordinates, then use tkplot.getcoords() to query the adjusted coordinates and then use plot() with these coordinates to create the PNG file.
library(igraph)
g <- graph.ring(10)
id <- tkplot(g, edge.width=1:10)
## Now adjust the coordinates by hand, and then continue.
## E.g. I moved vertex 7 to the middle
co <- tkplot.getcoords(id)
png("output.png")
plot(g, layout=co, edge.width=1:10)
dev.off()

images ds3.js heatmap

I am having trouble determining if you can create a heatmap with DS3 or R that can map onto a list of icons. Specifically wanted to use little people icons like these http://goo.gl/Yt8CG and then show concentrations of activity onto them. I am fairly new to data visualization with DS3.js and R so I might not be doing the right google-fu. Thanks ahead of time if anyone can show me an example or let me know if you CAN do shading on icons not just dynamically generated blocks like http://bl.ocks.org/mbostock/4063318
The basic approach is no different from drawing a normal heatmap (see for example here). The only difference would be that instead of appending rectangles, you append a container for the graphic that you want to use.
Whether you would be able to adjust the shading depends on the graphic itself -- if it's a bitmap you're out of luck. If it's an SVG for example you can simply select the path inside that SVG and set the fill color just like you would for a rectangle in a normal heatmap.

rgl plot: point size does not change when saving as postscript

I'm trying to generate a 3d scatterplot using rgl. It looks great on my screen, but whenever I export it as a PDF (or any other postscript format) it completely ignores any size specifications I use.
(I'm running RGui v.2.15.1 and rgl v.0.92.892 on a Macbook under Mountain Lion.)
For example:
library(rgl)
set.seed(1982)
points3d(runif(5),runif(5),runif(5), size=20)
# points look huge
rgl.postscript('testplot.pdf', fmt='pdf')
# points look tiny
Does anyone have an idea for a way to get this to work? The resolution of the images I get using rgl.snapshot don't look so good, and I would really like to get a vector image for this plot.
Also, I followed this thread and I got text to resize just fine, but not points. So I thought one way to work around this would be to plot my points as text using a circle as my character, but I couldn't get rgl to accept symbols or expressions either...
Confirmed on Windows, look like some paper size scaling problem. You might try
spheres3d(runif(5),runif(5),runif(5),radius=0.1)
as a workaround if you can live with real 3d.

How do I export a higher resolution image of a Mathematica Graph object?

How do I export a re-sized version of the output I get from a call to GraphPlot
(or TreePlot if they produce different output) to a jpg file?
Currently, I'm simply calling Export[file_name, G]
where G is the result from a call to something like GraphPlot.
I'm using Microsoft office picture manager to view the jpgs,
but re-scaling them there yields unsatisfactory results due to poor resolution
(the graph I'm trying to plot has strings as labels which can't be made out after rescaling this way). I would like to be able to choose the size/resolution of the rendered jpg.
As Simon already pointed out, don't use a raster-format for a vector-graphics. Instead, export you plot to e.g. a scalable vector graphics:
graph = GraphPlot[ExampleData[{"Matrix", "HB/can_292"}, "Matrix"]];
Export["graph.svg", graph]
The advantage is, that in such an image, you can still adjust and change lines, polygons and colors. And finally, you can export it to an image of arbitrary quality easily.
And remember, for Plots which contain lines, polygons, ... everything with sharp edges you should never use jpg. General speaking, this is a format for photographs only since its compression is made for reducing filesize in natural images. In those images you don't recognize the compression, in images with text, lines and polygons you certainly will notice the artefacts. Use png if possible. Take your browser and zoom into the above image.
You can set both image size and compression level of the exported file by doing something like
Export[file_name, G, ImageSize -> 1200, "CompressionLevel" -> 0]
The best way I find is to use ImageResolution property. It Increases the resolution of exported image but does not change the scale. Use it like this:
Export[ "image-file-name.png", image, ImageResolution -> 500 ]
Set the size of your graph before exporting it:
Graph[theGraph, ImageSize->2000]

Resources