Changing fonts in main title of plot in R - r

I am using Sweave and knitr together with <<dev="tikz">>= for figures. For simplicity, I first will try to explain my problem without providing a minimal working example:
I am using the command acf for plotting an autocorrelation function and want to change the font of the main title to e.g. font.main=1. I looked up the documentation which tells me that additional arguments of acf are the same as for plot.acf, which in turn uses the same as plot. Therefore I think font.main should work for acf as good as it does for plot. Unfortunately, adding an additional parameter for font.main in acf has no effect on the font of the main title. However, in plot this works fine. What is wrong here?

Something seems odd because the documentation of acf states that ... are "further arguments to be passed to plot.acf". And, the documentation of plot.acf further states that ... are "graphics parameters to be passed to the plotting routines".
This seems partially correct as passing font.lab and font.axis appear to produce the intended effect. However, font.main is ignored for reasons yet to be uncovered.
Until this gets fixed, the solution is to change the graphical parameters first, then run the command.
op <- par(font.main=1, ...)
acf(...)
par(op) # change back

Related

Holoviews - how to set legend click_policy for decimated points

I'm trying to set click_policy to 'hide' in legend_opts for the object resulted from applying holoviews.operation.decimate on a set of hv.Points, but it doesn't seem to have the desired effect.
Now I'm using the muted_alpha option on the underlying hv.Points to hide the points, but this is suboptimal, since hovering over the invisible points still shows the tooltip, which is cluttering the output when showing multiple curves.
I've tried passing legend_opts={'click_policy': 'hide'} as opts for the Overlay container, as well as for both the underlying hv.Points and for the result of decimate (actually, I also tried passing it as an argument to decimate), but to no avail.
I even tried using a hook for the bokeh plot as suggested here to directly set plot_obj.state.legend.click_policy = 'hide', but that doesn't work either.
So, any idea on how to hide a set of decimated hv.Points completely (i.e., not showing the hover tooltips either)?
Note: I've followed the "Principles of datashading" section of holoviews' user guide on "Working with large data" and used decimate as indicated there.
Turns out that one has to set the options for hv.Overlay after calling collate on it.

How to reset 'par' (pty='s') value in R

I was trying to plot two graphs simultaneously. I did it usingpar(mfrow=c(2,1) and reset the par to default with par(mfrow=c(1,1).
I was trying to make the size of dots in the scatter plot and ended in trouble. I mistakenly used par(mfrow=c(,1),pty='s') and my plot got re-sized instead of re-sizing the size of scatter dots.
Sorry since Im new to R; I want to reset the size to default value. ie, the value for pty='s' should go to default. How can I do that!! I tried with par(opar) and par(resetPar()) which I found from stackoverflow, but both returning could not find error.
Also, may I know how to increase the size of scatter dot(s)? Should I ask this as separate question?
Thank you for your help..
Before modifying the graphical parameters with par it may be useful to store the previous parameters:
old_par = par()
Then you'll be able to come back to previous settings by typing par(old_par). For your current problem, default value for pty is "m".
In any case, if you don't want to close your current graphical device to get the old_par parameter, you can still open a new one x11() then the par function will concern the new window, and then close it dev.off()

color.plot.phylo in PICANTE, how do you change size (cex) of tips or pass commands to plot.phylo?

I found the color.plot.phylo in the package PICANTE which colors the tips of your tree based on a trait. It's a great function, but I haven't been able to pass other commands to the phylo.plot function, as suggested.
I'm especially interested in changing the size (cex) of the tips and node.label.
Also, is there a way to move the legend?
This function wasn't written in a way that makes it easy to modify those graphical parameters, because certain parameters such as the location of the legend and the size of the text are both hard-coded in the function. If you are somewhat proficient at R you could modify the code of the function to change some of those values. For example, modify the following line in the function:
plot.phylo(phylo, cex = 0.8, tip.color = tip.color, main = main, ...)
to eliminate the cex value and then you should be able to specify different cex values as an argument to the function. You can find help on writing/modifying functions in R elsewhere on this site and in the R documentation.

Spatial plot error after changes to dataframe

I was using the following code to plot a spatial plot successfully:
colours<-(brewer.pal(7, "Blues"))
brks<-classIntervals(EDdata2$SIRt, n=7, style="fixed",fixedBreaks=c(0,1,2,5.0,10.0,20,50,120))
plot(brks, pal=colours)
brks<-brks$brks
plot(EDdata2, col=colours[findInterval(EDdata2$SIRt, brks,
all.inside=TRUE)], axes=F, border=FALSE)
However I made some changes to the spatialpolygonsdataframe EDdata2 by adding some extra columns and changing how SIRt is calculated (however it remains a column of numbers - they are just calculate differently)
Now when I try to run the plot code I get an error despite having made no changes to the plotting code:
Error in plot.default(...) : formal argument "axes" matched by multiple actual arguments
Whats going on here ?
That means that the package author of the unnamed package you used to create EDdata2 defined a plot method for whatever class EDdata2 might be that both used the axes argument and also used the triple dot mechanism to pass arguments to plot.default without filtering out that argument. (This does suggest that the package author didn't really want you to make your own axes, so you should investigate the help page for plot.whatever to see if it offers a mechanism for passing the values you want to use for 'at' and 'labels'.) You will need to do the spadework yourself (or edit your answer to make it more complete and reproducible) to investigate.
If this code is using the plot method for the SpatialPolygons-class in package:sp then the default value for axes is already FALSE.
help("SpatialPolygons-class", package="sp")
It is of course possible to mess this up by defining "F" to be something other than "FALSE" and then using axes=F. In the current instance it might be simpler to just remove that argument from the call.

Remove Legend In R

How I can remove the legend in a plot in R? I tried legend<-FALSE, doesn't work.
Also, is there a better way to set the position of the legend? For example, is there
a way I can pick the location with my cursor? And I am not talking about ggplot or any fancy add-ons, just regular R plotting.
In order:
This is related to what people tried to explain to you yesterday: Think of a script as primary means of creating your R session. In ESS, you get the script as a by-product; in RStudio you can also work with commands first and then pass those to your session. Lastly, no you can't remove a legend which has already been added to a plot, but you can hopefully re-create your graph using the saved commands.
Yes, since Duncan Murdoch added support for 'topleft' etc you can use logical commands:
plot(1:10) # simple plot
legend("bottomright", "foo") # 'foo' in bottom-right corner
Yes, if you use the output of locator() as input for the legend() command.
You need to specify which plotting function is producing the legend. (Most plotting function do not plot legends by default.)
There is a locator function.

Resources