How do I stop a ggplot graph legend from getting cut off on the right when exporting-saving when using showtext? - r

Just started R a couple weeks ago. Getting familiar with ggplot. I successfully made the graph I wanted to including all legends, axes titles, etc. I'm able to export/save this image fine. However, the assignment also required me to change the font used for the title, axes, legend text, etc. on the graph. To import the font I wanted to use, I used showtext as I saw this recommended when I Googled. When I use this, it does change the font to what I want. However, although I can see the entire graphs and its two legends fine in the Plot viewer, when I go to export it, the legend text is now cut off on the right. This appears to be the case as soon as I load the showtext package and use showtext_auto(), even if I just try to then recreate the graph using R's default font, not even with the new font. I've spent tons of time playing around and can't seem to resolve this. Please help. Also would be preferable if there is a more permanent way to get fonts into R rather than me having to load showtext and whatever font I want each and every time. Thank you very much.

Related

Julia Plots-GR, export to PDF, retain text editability

I am trying to save some figures I made in Julia (Plots package, GR backend) to PDFs and I love the aesthetics + being able to save as vector graphics. However, I may need to invariably tweak things in Illustrator. When in Matlab, the plots exported as PDF are by default editable, e.g. it is an easy few clicks to replace all fonts. Something similar can also be done for matplotlib.
So my question: how can I export to PDF with editable text (this means something like Illustrator will treat text as text instead of paths) using the default backend?
Googling around, it seems the same matplotlib hack above might work in Julia via Plots.pyrcparams, but I am afraid to change backends and then have to fix a dozen plots because things broke.

How to Change X-Axis Label in ChromoMap?

I am new to R and I have been using chromoMap library in R to visualize annotation plots and visualizing the feature-associated data. It's a great library and produces great charts. However, I was not able to find any option for changing the x-axis label from length (bp) to anything else. Because of this, I am not able to use any of the produced charts. It sounds like a small issue, but it totally affects the usability of this great package. I followed this tutorial link and produced the below chart. In my chart and all the samples, the x-axis label is fixed and this is my problem and I am looking for a way to just change it.
library(chromoMap)
chr_file_1 = "chr_file_without_centromere.txt"
anno_file_1 = "annotation_pos.txt"
chromoMap(chr_file_1,anno_file_1)
I am wondering if anybody has the same experience ?? This package produces output as a htmlwidget object and therefore I could not change the x-axis lable. Is there any way to modify a htmlwidget object? or Any way to change this bp to something else??

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.

Can R create a barplot image with clickable bars to insert on a webpage?

I know how to create a barplot, and how to stick it on a webpage; e.g, using hwriteImage in the hwriter package.
What I'd like is for each bar to be a region which highlights on mouseover, and where each bar has a different link when clicked. Similar to this map of the U.S. using the jQuery maphilight plugin, but for a barplot rather than a map. I imagine R could calculate the coordinates of the regions around each bar, generate the HTML AREA tag etc and pass this to maphilight quite easily. Has it been done already? I searched but no luck so far.
Have a look here, which summarises a couple of methods: rggobi and iplots. rggobi looks pretty promising, though maybe the installation looks a bit involved. iplots is only good for scatter plots.
Some other options (I think these are strongest ones at the moment):
googleVis
The googleVis package interfaces with the google charts API: try demo(googleVis) and the third & fourth one are bar chart (there could be more). It has the advantage of being pretty simple to get started with, although these are not R graphics:
df=data.frame(country=c("US", "GB", "BR"), val1=c(10,13,14), val2=c(23,12,32))
Column <- gvisColumnChart(df)
plot(Column)
gridSVG
The gridSVG exports the current grid graphics to an .svg file that can be included into a webpage. Unlike googleVis, it's R graphics (so you can use grid/ggplot2 which are more familiar). It looks like you may have to know some Javascript to further embellish your plots though (e.g. to animate on mouse over, you use grid.garnish(...,onmouseover=...)).
There's some example code you can try here (The really awesome ones are here - usually clicking on the "SVG file" link will have the full interactivity/animation.) (This one is a scatterplot where the points highlight when you move your mouse over them).
As I said - have a look at the package pages, demos, examples, etc to see which suits you.

Is there a way to replace the legend or axis without redrawing the whole plot?

Sometimes I will place a legend at a particular location on the plot, let's say topright, and then I see that it covers an important part of the plot. Is there a way I can switch it to topleft or some other place without having to run all the other commands first? Sometimes I have the same problem with the axes, I misspell a word and then I have to issue all the commands again.
I eventually place everything in an R script which means this becomes less of a problem, but sometimes I want to quickly test something in console. Please tell me I have overlooked a basic command that does this.
There is no such thing, but you're on the right track - a script is definitely the way to go. I would also recommend R Studio, a free R IDE, which gives you several displays, one for scripts, one for the console, one for your plots - it's great! It makes working with scripts as easy as interacting with the traditional R console.
As Gabriel told you, a script is the best way. However, the following link could help you:
Using Inkscape to Post-edit Labels in R Graphs

Resources