How to avoid collision of text in basic R? - 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.

Related

R: interact with customized XML map

A Stack Overflow discussion here (How to make a heat map in R based on a gif of the human body?) describe how to plot a map for different part of human body in R.
I want to make the plot more interactive, i.e. if I move the cursor to the torso, I want to see a message "torso".
In other words, what I want to do is similar to the "identify" function for scattor plot, but is for plots generated from XML.
Another example for what I would like to achieve is: https://plot.ly/r/choropleth-maps/
Thanks!

How to draw pie of pie or bar of bar charts in R (using ggplot2)? [duplicate]

I know it is possible to create such double pie charts in excel like this:
http://chandoo.org/wp/2009/12/02/group-small-slices-in-pie-charts/
but can SPSS or R do this also?
In relation to R:
The answer to the title question is "yes" ... see ?pie
As for the second question, the one in the body - it would be possible but would involve some coding. You'd have to draw two pie charts side by side (which could be managed with two calls to pie) and use segments or arrows (and text if necessary) to do the additional components of the plot.
Here's a rough example:
That required the fig argument of par to get them side-by-side.
(That example required a little fiddling to get right, but it would be possible to write a function to automate the details.)
The main issue I can see would be 'why on earth would you do it?' -- pie charts are a poor way of conveying information of this form. There are alternatives that result in much better ability to distinguish values, and less bias (such as what you get when comparing nearly horizontal vs nearly vertical slices).

Defining polygon coordinates with a predefined image and plotting in R

Here is what I need: I have an image and want to plot on specific rectangle-shaped parts of it (e.g., imagine having a picture of a chessboard and wanting to fill every square with a different color). I would like to be able to easily specify the coordinates for these parts and take these coordinates into R for plotting.
I don't have any experience with making such plots. I've thought of simply inserting an image into a plot with rasterImage (), then plotting with polygon (), but the task of setting up the coordinates for the polygon function seemed too time consuming - hence the question above.
If you have any better ideas than using a set of coordinates for the polygon function, please share. Any leads or packages suggestions would also be helpful.
thank you. Marko.

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.

Placing grid tables in R

I want to use grid.table() in an existing plot in R. However I can't locate this table on the right side of my chart. So the thing is:
First of all, I make an histogram of my data:
hist(as.numeric(unlist((vels[counts]))),freq=F,
col="gray",border="black",ylim=c(0,0.15),
xlab=paste(names(vels)[counts]),
main=paste("Weibull fitting",names(vels[counts])))
After that, I have implemented a function that plots in an existing chart the Weibull curve giving both parameters A and K:
plot_weibull(K_value,A_value)
And finally I want to place a data.frame using the grid.table() because it shows the cells in a very pretty form, and you can use italic and bold text in cells.
grid.table(round(values,3),cex=0.75,show.rownames=T,
show.colnames=T,show.hlines=T)
The problem is that this table appears in the center of the device in front of the histogram and the curve, and I want it to be in the right side.
After all, I would like to know a tool that clicking on the graph, I would receive the area under my Weibull curve.
The hist function is base graphics and the grid.table function is grid graphics. The 2 graphics systems do not play nicely together without extra effort (as you have noticed).
The easiest fix is to use the addtable2plot function from the plotrix package rather than grid.table. It may not look the same but it would be simple.
Another option is to use a grid graphics function to create the histogram, such as something from the lattice or ggplot2 packages (both can do histograms), then create a specific viewport using grid graphics functions and use grid.table to put the table into that viewport.
Last, if you really want to mix them then see the gridBase package for ways to mix grid and base graphics.

Resources