This question already has answers here:
R Language: How to Set ylim?
(2 answers)
Closed 4 years ago.
I have this graph which I'm plotting
As you can see, the values on the black line which I'm trying to plot is not on the same scale as that of the red line.
Therefore, I'm trying to change the scale of the Y-Axis, so I can essentially "Zoom Out". How do I do this?
What I did till now is:
plot(d,vol1, type="l",xaxt="n", xlab="Date", ylab="Volatility Estimate", main="Nasdaq Pharmaceutical Index")
months= seq(min(d), max(d), "month")
axis(1, months, format(months, "%Y\n%b"))
lines(d, vol1, col="black")
You can add the argument ylim=c(a,b) inside the plot() command, where a is the minimum and b is the maximum of your desired y-axis.
Related
This question already has answers here:
How to change x-axis tick label names, order and boxplot colour using R ggplot?
(2 answers)
Closed 4 years ago.
I would like to customize my own x-axis using plot in R. What i want is that the x-axis would display 40-52, then from 1-40 again, something in the attachment shown below. My data is from 2015 week 40 to 2018 week 4, and I have tried something like 2017_40 to 2018_4, but this will make the graph look really cramped.
Use xaxt='n' in your plot to suppress printing the x-axis, then use axis to print whatever you want.
x = 40:92
y = sin(x)
plot(x,y, ylim=c(-2,2), type='l', xaxt='n')
xlab = ifelse(x>52, x-52,x)
axis(side=1, at=40:92, labels=xlab)
This question already has answers here:
Set R plots x axis to show at y=0
(2 answers)
Closed 3 years ago.
I observed that the x axes of a plot doesn't cross the y axes at 0.
Why?
How can I fix that?
Example:
plot(mtcars$mpg, ylim=c(0,50))
By default, R extends the axes by 4% on either end around the limits: from ?par,
‘xaxs’ The style of axis interval calculation to be used for the
x-axis. Possible values are ‘"r"’, ‘"i"’, ‘"e"’, ‘"s"’,
‘"d"’. The styles are generally controlled by the range of
data or ‘xlim’, if given.
Style ‘"r"’ (regular) first extends the data range by 4
percent at each end and then finds an axis with pretty labels
that fits within the extended range.
Style ‘"i"’ (internal) just finds an axis with pretty labels
that fits within the original data range.
(yaxs does the same thing for the y-axis).
You can use
plot(mtcars$mpg, ylim=c(0,50), yaxs="i")
This question already has an answer here:
How to remove default axis from the plot produced by boxplot()?
(1 answer)
Closed 8 years ago.
I'm trying to change the names of the column labels on the x axis of a boxplot.
This is my code for the graph:
boxplot(datab~area,ylab="Heather Cover (%)",xlab="Survey Area")
axis(1, at=1:3, lab=c("Hangars", "East", "Runway"))
This works, however, the old column names (1,2,3) remain underneath the new labels. How do I get rid of these?
One thing you can do is remove the x-axis labels using xaxt="n" in the original plot. Let me illustrate using the "mtcar" data.
boxplot(mpg~gear, data=mtcars, xaxt="n")
axis(1, at=1:3, lab=c("Hangars", "East", "Runway"))
This question already has answers here:
How to create a line plot with groups in Base R without loops?
(3 answers)
Closed 9 years ago.
here is my question.
I would like to make a scatterplot which (x,y) pairs are connected by line.
I have three treatments A,B,and C
A<-c(103.4,102.5,101.4,101.0,98.8)
B<-c(102.9,101.6,101.4,100.3,99.6)
C<-c(103.9,103.1,102.3,100.4,97.6)
These 3 variables are going to be plotted on the y axis (Temperature)
And I also have a variable for the x axis (Minutes)
M<-c(15,30,45,60,75)
I just would like to know how to make a plot using different lines and symbols for the 3 different treatments.
Thanks so much!
png() # default file name is "Rplot001.png" in your working directory
matplot(M, cbind(A,B,C), type="b",
xlab= "Minutes", ylab=expression(Temperature~degree*F),
xlim=range(M)+c(-5,5), ylim=range(c(A,B,C)) +c(-1,1) )
dev.off()
# See ?legend and ?title for further annotation
This question already has answers here:
How to specify the actual x axis values to plot as x axis ticks in R
(4 answers)
Closed 9 years ago.
Let's say I have some points:
a=c(1.234, 23.332, 3.433, 34.53)
b=c(112, 234, 221, 23)
I would like to plot them by having "a" on the x axis and "b" on the y axis.
plot(a,b)
This will give the resulting plot, but what I would like to do is rather than display some interval on the x axis I would like to display the exact numbers that I have, i.e. the values of a.
Is this possible?
Jup.
plot(a,b, xaxt="n")
axis(side=1, at=a)
or maybe
axis(side=1, at=round(a,2))
for aesthetical reasons.