`yaxp` is no longer working like it used to - r

When I teach histograms using R, I use the yaxp parameter to adjust the y-axis. Here is an example of the code:
hist(bookspending$'Dollars on books', yaxp = c(0,9,9))
This produces a histogram where the y-axis has tick marks at 0, at 9, and a tick mark at every integer in between. Here is a picture of it:
I'm using Rstudio version 1.4.1717 and R version 4.1.1. This has worked the past 4 years. This semester the yaxp parameter isn't working for some students. I replicated the problem using the web-based version of R. Using the same code, the yaxp parameter makes no changes to the histogram. Here is the picture:
Why does yaxp no longer work for the online version, but it works for my version? How do you adjust the y-axis without yaxp?

This happens because there was a change in the function graphics:::plot.hist in R version 4.2.0.
Previously, the part of the function that controlled the drawing of the axes was simply:
if (axes) {
axis(1, ...)
axis(2, ...)
}
But it has been changed to
if (axes) {
axis(1, ...)
yt <- axTicks(2)
if (freq && any(ni <- (yt%%1) != 0))
yt <- yt[!ni]
axis(2, at = yt, ...)
}
Which means that the y axis breaks are now decided solely by the output of the function call axTicks(2). Your yaxp argument is still passed to axis, but unfortunately, specifying at nullifies yaxp.
This is sort of mentioned in the CRAN R News, where it says:
hist.default() gains new fuzz argument, and the histogram plot method no longer uses fractional axis ticks when displaying counts ("Frequency").
So the reason for the change was to prevent fractional axis ticks, but a side effect of this was preventing users from specifying y axis breaks. The only work-around for now it would seem, would be to add the axes manually as suggested in the last set of comments.
You may wish to file this as a bug report, since it seems to me that it should be possible to specify axis breaks and disallow fractional breaks without much difficulty.

Related

Tick marks inside with image function with R

I am trying to have the tick marks inside my plot with R image function.
I red a fits image and I represented it into a PDF file using the "image" function in R. The result is fine, but the tick marks are outside the plot and I want them pointing inside.
image(1:dim(imn2223J)[1], 1:dim(imn2223J)[2], imn2223J, zlim=c(-8,15), asp=1, col=rev(rainbow(100)), xlab= "X - Arcsec", ylab="Y - Arcsec",cex.lab=2.5, cex.axis=2.5)
I have succeeded to have other tick marks inside, but the original ones from image are still there pointing outside. Someone encountered this prb ? Thanks.
Most base graphics functions like image() accept graphical parameters in the ... arguments. Those are documented in ?par. The one you want is tcl; positive values point into the plot. The default is tcl = -0.5, half a line of text pointing outwards. For the same length pointing inwards, use tcl = 0.5.

How to change the precision of ticks in julia plot

I'm plotting in julia for the first time and have installed the Juno IDE. I'm plotting with Plots.jl and every time I plot, the y-axis tics have lots of decimals.
I've tried multiple backends, like GR, Plotly, PlotlyJS, but none have changed the behavior I'm seeing.
This is the code I have currently producing my results:
using Plots
gr()
x = 1:10; y = rand(10)
p = plot(x,y)
And the figure that's output:
https://github.com/bojohnson02/Random/blob/master/fig.pdf
That's a temporary bug caused by some changes to Showoff, the package that Plots uses to create the axis ticks. It should be fixed already, so updating your packages should work (]up). If it doesn't work yet, and you're in a hurry, installing master of the two packages should do the trick (] add Plots#master followed by ] add Showoff#master).

plot function type=ā€œnā€ is ignored for plot(y~x)?

I am trying to plot a graph of certain values against time using the plot function.
I am simply trying to change the representation of the dots, using the pch= function. However R is simply ignoring me! I have also tried removing the dots so that I can place labels instead, but when I type in type="n" it ignores that too!
I am using the exact same format of code that I have used for other plots but this time it just isn't cooperating.
If I specify other features such as the title or the x/y axis labels, it will add those in but it simply ignores the pch or type commands.
This is my basic code:
plot(Differences ~ Time, data=subsetH)
But if I run
plot(Differences ~ Time, type="n", data=subsetH)
or
plot(Differences ~ Time, pch=2, data=subsetH)
it keeps plotting the same thing.
Is there something obvious I have missed?
I just came across your question because I encountered the same thing - creating an empty plot did not work, as type='n' was always ignored (as well as other type specifications).
With the help of this entry: Plotting time-series with Date labels on x-axis
I realized that my date format needed to be assigned as "date" class (as.Date()).
I know your entry dates back a little bit already, but maybe it's still useful.

Omitting y-axis ticks (and labels) in base R

The Question:
Imagine I am making a simple plot: plot(1:5,1:5,ylab = "y-axis"). Here, the y-axis (well actually both axis) are not only nicely labeled, but they both have tick marks with labels. How would I go about making a plot with neither tick marks nor tick mark labels?
What I've tried
The first thing I've tried was removing the margins to the left of the graph, while this effectively worked, it was a bit hacky and didn't get at what my actual problem was. I then continued to dive into the par specifications. Setting par(tck = 0) removes y-axis tick marks, but does so by removing all tick marks on the graph - this isn't ideal. I also tried par(ann = FALSE), and par(cex.lab = 0.001, cex.axis = 0.001) which also did not work.
I'm pretty sure the answer to my question is burried somewhere in the par specifications but for now, unfortunately, I will have to stick with removing the left margins to 'cut off' these undesirable labels.

R metafor forest-plots: xlim seems to be wrongly ignored

I am using forest.rma in the R package metafor. I want to use the xlim argument to specify the width of the plot. But this gets overridden when one of the x-values is outside that range. Here are two examples:
library(metafor)
par(mfrow=c(2,1))
rmaObject <- rma.uni(yi=c(1.3, -16), sei=c(0.8, 0.7))
forest(rmaObject, atransf=exp, xlim=c(-5,12), alim=c(-5,12))$xlim
forest(rmaObject, atransf=exp, xlim=c(-5,12))$xlim
In both cases I think the function should follow my instruction to use xlim=c(-5,12) and draw just a left arrowhead for the second bar, to show that the whole of the bar lies outside the left of the plot. But as the console output shows the first one sets xlim to c(-16,12) and the second one sets it to c(-20,12).
In other words forest forces xlim to encompass both bars completely, but I don't think it should do that if I specify xlim, and especially not if I specify alim as well. Is there an easy way for me to fix this?
The numbers in this example are real, though I have omitted most of my studies (i.e. values of yi and sei), which are mostly in the area of 0 or 1.
You can install the development version of metafor as described here:
http://www.metafor-project.org/doku.php/installation#development_version
It deals with this better. It still forces xlim to encompass the yi values, but no longer for alim. The summary polygon at the bottom still looks like crap though (I haven't built in any code to cut off the polygon shape at the alim values -- not as trivial as it may seem), but this may not be an issue once you add the rest of the studies.

Resources