R / d3heatmap - is there a way to rotate the axis label? - r

In the R d3heatmap package, is there a way to rotate the x axis label to be 90 degrees (perpendicular to the axis) instead of 45?

I couldn't find an easy option to pass a rotation value to the function, but you can go into the innards of the d3heatmap package and change the rotation in the javascript code.
Run ".libPaths()" in R to find where your R packages and their data are stored. In my case I found the d3heatmap package in '/home/nick/R/x86_64-suse-linux-gnu-library/3.1/d3heatmap/'.
The file you are looking for is something like '/home/nick/R/x86_64-suse-linux-gnu-library/3.1/d3heatmap/htmlwidgets/lib/d3heatmapcore/heatmapcore.js'
Open the file with a text editor. There are two places where there is a setting: "rotate(45),translate(6, 0)".
So search for "rotate(45)" and replace "45" with "90" in both places. You'll also have to change "translate(6, 0)" to something that places the text better. I found that "translate(12, -20)" (shifting the text down by 12 pixels and right by 20 pixels) worked well using the "mtcars" dataset as a test.
d3heatmap with vertical row labels
When using datasets with more or less rows, you'll have to play around with the right translation, changing it a bit from -20 so that things align correctly. There is probably a way to do this automatically, but I mostly just know R, not javascript, so I don't know how to do it.

Related

How to avoid collision of text in basic R?

text() puts text at specified coordinates. But some texts may overlap each other. How to wiggle the position of the text automatically so that they don't overlap?
The solution must be in basic R instead of using another R package as I will need to combine this with other basic R drawing commands to customize my drawing. Or the solution should provide a way to compute the wiggled coordinates. It should not directly draw the texts so that I can not combine it with my other drawing code in basic R.

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.

image manipulation package in R need

Please advise some R packages on rotating or flipping image on R.
Thru package and , i'm able to read pic and turn into matrices (or data frame), however, duto the angle of shooting, the photo is tiled (or not directly facing me). I would like to manipulate the data, so I can adjust the angle.
My plan is to define the normal line of the left pic, and recalculate the angle, but failed. Guess there could be some image manipulation packages for this.
Have tried the CRAN TASKS, yet, most of the packages are for creating images, not to manipulate the outside-in images.

Extracting boundary line from Image in R

So I got some kind of cross section picture in jpg format I want to work with. For better understanding I just drew a picture, hopefully symbolising well enough kinda how the real pictures will look like:
At the top of the picture is material A, at the bottom material B.
Goal: I want to get the Pixels of the boundary line between both materials.
My way so far:
I already know how to read pictures with package called EBImage
I also know, that this will result in a matrix with a color value for
every pixel.
I thought it would be better to convert the jpeg into a binary picture with only black and white colors.
I thought filling up the black part below (Material B) and reducing the noise would be nice, so I could use column sums (a sum of 1's) to find the row number where material A touches material B, which should be my searched boundary line (right?).
Problems:
I don't find filters which fill up the black parts intelligently, in the real pictures, there will be much more noise, which will complicate things even further...
I am not sure if all this is even necessary, and there is a more efficient way to reach my goal of finding the boundary line
Thank you very much for every tip in advance!
Answers will always be vague when there's no example to work with. I would normally use ImageJ for a task like this but EBImage has the commands that I would use.
From EBImage I would make binary and then erode , dilate, and fill holes (fillHull).
Your picture looks like it might be a candidate for a support vector machine. There are a couple of packages for R with svm functions, one is e1071.

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.

Resources