Good morning, i have the next code:
plot.zoo(ResultadosLP, plot.type="m", ylab = c("Spread", "Mid_Rqs", "L_Rqs", "Mid_QP","Ef_Spread","Mid_Res", "L_Res", "IRC"), cex.axis=0.65,xlab = "Fecha(periodicidad mensual)"
I want to round the numbers of my axis y because I got 4 digits, and I need only one digit in the plot, how can I do that?
Note: it is a multiplot, and if you could give me other advice to solve the problem of size, I appreciate so much that. I tried cex.axis, but I can't keep going because is too small.
Thanks
Try calling signif() on the variables in ResultadosLP you're plotting on the y-axis before you plot it. You can set the argument digits = 2
Related
In my plots I try to replace the axis labels with value 'Inf' with the infinity sign (e.g. unicode '\u221e'). Since I have many plots with different labels, I don't want to do it by hand.
I thought it would be easier to use unicode than plotmath. However I can't figure out how to reach my goal. For example, I have the following vector:
xlab <- as.character(c(1:10,Inf))
x <- y <- 1:11
plot(x,y,xaxt="n")
axis(1,at=x,labels=gsub("Inf","\u221E",xlab))
axis(3,at=x,labels=gsub("Inf","\\u221E",xlab))
both don't work. What am I missing? Thank you for your help!
Edit on 2018-02-06:
I was wrong, rawr's solution works only halfway. I think I need to clarify my problem a bit more.
1) I have many different plots (with different x, y and corresponding xlab values) that I want to loop over. That's why I try to use a sub/gsub solution, because I don't want to write a hundred times the labels.
2) My first example (axis(1,at=x,labels=gsub("Inf","\u221E",xlab))) is not working on any of my windows machines. It is working on debian, though.
3) rawr's solution does have the problem that it annotates all available labels, no matter how much space there is available for annotating. Simple example:
x <- y <- exp(-1:11)
xlab <- as.character(c(Inf,10:-1))
plot(x,y,xaxt="n")
axis(1, at = x, labels = parse(text = gsub("Inf", "infinity", xlab)))
is not that nice.
Is there any solution for my windows machines? Possibly not by code, but by changing some settings?
Thanks!
Try
axis(1, at=x, labels=c(1:10, expression(infinity)))
A more flexible approach that can handle any unicode character is available using the stringi package:
axis(1, at=x, labels=c(1:10, stri_unescape_unicode('\\u221E')))
I am trying to have R shiny print out the sample information when hovering over a data point in a ggplot2 geom_point plot. The axes for my plot have 4 decimal points but if I print plot_hover$x and $y it only returns two decimal points, so the output ends up being the same for every point on the plot. I noticed the examples on the shiny site also only output two decimal points. Is there a way to change this to retain more information in input$plot_hover?
Without a reproduceable example this is tough, so all of these are complete guesses as to what your actual problem is. Here are some stabs in the dark as to how to fix a problem where ggplot is not printing enough digits.
#HubertL: You may be able to control the number of printed digits using
options(digits = 10)
Or use a wrapper around any calculations to specify the number of rounded digits to include in a calculation or output from a function
round(calculation, 10)
Additionally, this could be an issue with the space on the plot axis. You may want to try decreasing the size of the text on the axis within the plot using
plot + theme(axis.text.x = element_text(size = 8))
And you could add angle in there as well to rotate the numbers to validate there is enough space.
I want to do a simple plot using Plots.jl.
I calculated a rate for each month over a couple of years. The problem that I am facing now is that I want to add a trendline to this plot. I did not find how this is done in Julia or Plots, if this is somewhere, please tell me.
My second question is that as I just get a vector with lets say 150 elements, each for a month, Plots.jl just gives me numbers on the x-axis for 0, 50, 100 and 150 with horizontal lines. I would like to change this to every 12 numbers one of these lines plus the year as a label on the axis.
I hope my question is clear, and thank you very much in advance.
Cheers
No fancy features needed if I understand your question correctly.
using Plots
dates = 1:150
ticks = 1:12:150
ticks_labels = 0:12
values = rand(150).+dates*0.01
plot(dates, values, xticks = (ticks, ticks_label), label="my series")
bhat = [dates ones(150)]\values
Plots.abline!(bhat..., label = "trendline")
output ->
Plots now has a simple keyword option for adding a trend line.
using Plots
scatter(collect(1:10),collect(1:10)+rand(10),smooth=:true)
I often determine that when plotting in R not all relevant tick-marks are drawn. Relevant here means that there is data present.
See this example
> set.seed(NULL)
> d <- data.frame(a=sample(1:10, replace=TRUE), b=sample(11:30))
> plot(d)
The resulting plot where you can see values on the X-axis at 3, 5, 7 and 9. But the tick-marks for them are missing.
The focus of my question is to understand why R acts like that. What is the algorithm and logic behind it?
btw: I know how to solve it. I can draw the X-axis myself. But that is not part of the question.
You could find a brief description of the algorithm for plotting the tick marks using?axis.
plot() is a generic function to plot a wide sort of data. In your example, you are using discrete data. For continuous data, it does not make much sense to have a single tick mark for every single value, which would make unreadable the axes.
However, you can easily adjust the ticks in your plot using axis()
I have generated the following histogram in R:
I generated it using this hist() call:
hist(x[,1], xlab='t* (Transition Statistic)',
ylab='Proportion of Resamples (n = 10,000)',
main='Distribution of Resamples', col='lightblue',
prob=TRUE, ylim=c(0.00,0.05),xlim=c(1725,max(x[,1])+10))
Plus the following abline():
abline(v=1728,col=4,lty=1,lwd=2)
That vertical line indicates the actual location of a test statistic, which I am comparing to the results of permutation samples.
My question is this: as you can see, the x scale does not extend back to the vertical line. I would really like it to do so, because I think it looks odd otherwise. How can I make this happen?
I have already tried the xaxs="i" parameter, which has no effect. I have also tried making my own axis with axis() but this requires making both axes again from scratch, and the results don't look that great to me. So, I suspect there must be an easier way to do this. Is there? And, if not, can anyone suggest what axis() command might work well, assuming I want everything to look basically the same, but with the longer x scale?
The usual R plot draws a frame around the plot. To add this, do:
box()
after the plot.
If that isn't what you want, you need to suppress axis plotting and then add your own later.
hist(...., axes = FALSE) ## .... is where your other args go
axis(side = 2)
axis(side = 1, at = seq(1730, 1830, by = 20))
That won't go quite to the vertical line but may be close enough. If you want a tick at the vertical line, choose different tick marks, e.g.
axis(side = 1, at = seq(1725, 1835, by = 20))
Since R is using gaps of 20 for the x-axis here, you can get the extension you want using 1720 rather than 1725 for the lower limit , i.e. with xlim=c(1720,max(x[,1])+10) which would produce something like