putting text next to a plot in R - r

I have a plot with many "lines" in it (using points with type being l).
I would like to put a small piece of text next to them. I could do that all sort of ways, such as using mtext, but the problem is that there are many plots to be generated automatically, and there could be many lines in a single plot, so I would like the text to be placed automatically close to the line in an empty spot...
Is there a way to do that?

Related

How to line up bars on a plot in markdown?

I'm using r-markdown to make one pagers. I have all my plots set in place but they do not line up nicely. The plots area is lined up but where the bars start is different for each plot. How can i set it so that it's always lined up? I want to line up the green lines.The start of the plots (maroon line) is always in line.
NB! The two plots are made separately from one another as they use different data.

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.

text() in R on plot - how to keep on a single line without wrapping?

I often use R to run batch jobs that contain PDF outputs with scatter plots produced using a combination of plot() and points(), among other graphical functions. (I don't use ggplot2 much and would like to avoid using it for this question.)
When using the text() function in a plot in order to add text near a plotted symbol, I like to use the pos = 4 option to right-justify text next to say a symbol like pch = 23 (filled diamond). But I've noticed that sometimes the text will get wrapped as part of multiple lines, and other times it stays on a single line. Unfortunately when the lines are wrapped it causes text overlap problems. Why does text() sometimes wrap text on multiple lines?
Is there a way to force R to keep the text added to a plot from text() on a single line?
Here is my code:
text(x=data_frame_w_data_to_plot$x_axis_value,
y=data_frame_w_data_to_plot$y_axis_value, labels=data_frame_w_data_to_plot$text_to_plot, col="black", cex=1, pos=4)
Answering my own question here. Found the text string of "\n" just happened to be in one of the cells, and simply used gsub() to slightly modify this cell. This solved the problem. Learn from my mistake. :)
data_frame_w_data_to_plot$text_to_plot <- gsub("\n", " ", data_frame_w_data_to_plot$text_to_plot)

Hyperlink like plots in R

Is there a package in R where if you have a line graph, and you click on one of the lines, it will take you to another graph?
So basically I want to portray a large scale view of paramters and then when I click on one of the lines in the graph, it will take me to a more detailed look at the data in a different graph created.
If that isn't possible, then a text hyperlink in the legend would be fantastic.
Thanks!

LocusZoom standalone change x-axis and use the plots in a script

I am using the standalone LocusZoom software,but I am having two problems:
I have to create a plot showing only position on the x-axis (not showing the genes). If I just use showGenes=FALSE with nothing else the genes still appear, but if I use rfrows=0 then the genes are not shown, but the problem is that also the x-axis label with the positions disappears. Is there a way to only show the position label? It looks like the only way to do this is to modify the original script...
Is there a way to use several plots created using LocusZoom in an R script to position many plots into one unique figure? (output is a pdf for now) There is an option listed in the LocusZoom webpage (http://genome.sph.umich.edu/wiki/LocusZoom_Standalone) called "prelude" but I cannot get more info on how to use it.
If you have any suggestions for either of these two issues it would be very helpful! Thanks!!

Resources