this is the first example of the ecdf() function in R:
F10 <- ecdf(rnorm(10)
plot(F10)
plot(F10, verticals = TRUE, do.points = FALSE)
Now I would like to "zoom" in the y-axis so that it only shows the interval of 0.9-1.0.
Does anybody know how to accomplish this? Thanks a lot in advance!
Thanks to rbm this is the easy solution:
plot(F10, ylim=c(0.90, 1.00))
Related
I need to plot two sets of data on one graph, and then use locator() to draw a vertical line at a given date. I have the code below and it works until after the plot function. The lines function is not adding the second dataset to my graph.
Can someone please help me understand what I'm doing incorrectly?
Thank you in advance
LMT <- read.csv("LMT.csv",header = T)
JNJ <- read.csv("JNJ.csv",header = T)
LMT$Date <- as.Date(LMT$Date)
JNJ$Date <- as.Date(JNJ$Date)
plot(y=LMT$Adj.Close, x=LMT$Date, ylim = c(0,500), type = "l")
lines(JNJ$Adj.Close,type = "l")
With the following code I plotted the Cross Correlation of my data. All works wonderful, however the visualization does not depict Lag 0, which is highly important for my studies.
p= ggCcf(
df_ccf$Asia_Co,
df_ccf$EU_USA,
lag.max = 10,
type = c("correlation", "covariance"),
plot = TRUE,
na.action = na.contiguous)
plot(p)
The plot is looking like that:
Head of data:
I encountered the same issue; it might be an issue/bug with 'ggCcf' from the forecast library. I couldn't get ggCcf to work, no matter what I tried. Anyone who wants to reproduce this behaviour, try:
ggCcf(c(1,2,3,4),c(2,3,4,6))
The workaround is using regular/base R ccf:
max_lag = 10
result = ccf(series1, series2, lag.max = max_lag)
y = results$acf
x = c(-max_lag:max_lag)
You can use these two series to plot the ccf using ggplot2 and choosing an appropriate ylim.
The downside of this all is less conveniance, but the upside is that you can add some flair/styling to your plot now that you are doing everything yourself anyway ;).
I am trying to perform sliding correlation with window=11years.
Here's my code:
library(gtools)
var1<-rnorm(52,0.010,0.05)
var2<-rnorm(52,0.015,0.01)
dat<-merge(var1,var2)
dat$year<-seq(1961,2012,1)
rc<-running(dat$x,dat$y,fun=cor, width=11)
I want to plot the output as a simple line plot like this:
plot(rc,type="l")
My problem is the x-axis. How do I match the correlation value with the years? Something like adding a filler value "0"?
Any suggestions on how I can do this correctly in R.
I'll appreciate any help.
Many thanks in advance.
rc <- running(var1, var2, fun = cor, width = 11)
plot(1971:2012, rc, type="l")
I tried to visualize a Power Law p(x)=x^(-2.5) with following R code. When you use an log-scale in the end you get a lot of vibrations what is okay as can be seen here
But know, and this is my Problem, I read an article where the author says I have to use a cumulative distribution function to remove this vibrations at the end. But for me it doesn't work, as can be seen here
library(ggplot2)
chol_r <- read.table("C:\\Users\\me\\Desktop\\1M_just_random_py.txt",
header = FALSE)
chol <- (chol_r)**(-2.5) #this p(x)
chol2 = (1/1.5)*chol_r**(-1.5) # the cumulative distribution function
qplot(chol2,
geom="histogram",
binwidth = 0.001, #0.001 oder 0.38
main = "Histogram",
xlab = "Numbers",
fill=I("blue"),
col=I("red"),
log="xy")
So does anybody know what I am doing wrong? Or how i can get a straight line falling without that vibrations? I really don't know what I am doing wrong
I'm trying to generate boxplots in R that display the 95% confidence intervals of the mean but I can't find any way to display this statistic. I typically use ggplot2 for data visualisation in R but I'm open to using another package if necessary. Does anyone have any suggestions on how to do this? Thanks.
Here is an ideia, with normal dist:
set.seed(123)
a = cumsum(rnorm(100))
n=length(a)
mm=mean(a)
dd=sd(a)
error <- qnorm(0.975)*dd/sqrt(n)
inf <- mm-error
sup <- mm+error
boxplot(a,col=3)
lines(c(0.75,1.25),c(inf,inf),col=4)
lines(c(0.75,1.25),c(mm,mm),col=2,lwd=2)
lines(c(0.75,1.25),c(sup,sup),col=4)
legend("topleft", c("95% CI", "Mean"), lty=1,col = c(4, 2),bty ="n")