[R] Error bars and CI

Mohan.Radhakrishnan at cognizant.com Mohan.Radhakrishnan at cognizant.com
Mon Jun 15 12:51:29 CEST 2015


Hi,

I want to plot a line graph using this data. IDX is x-axis and V1 is y-axis.  I also want standard error bars and 99% CI to be shown. My code is given below. The section that plots the graph is the problem.  I don't see all the points in the line graph with error bars. How can I also show the 99% CI in the graph ?

      V1 IDX
1  0.987  21
2  0.585  22
3  0.770  23
4  0.711  24

library(stringr)
library(dplyr)
library(ggplot2)

data <- read.table("D:\\jmh\\jmh.txt",sep="\t")

final <-data %>%
           select(V1) %>%
              filter(grepl("^Iteration", V1)) %>%
        mutate(V1 = str_extract(V1, "\\d+\\.\\d*"))

final <- mutate(final,IDX = 1:n())

jc <- final %>%
              filter(IDX < 21)


#Convert to numeric
jc <- data.frame(sapply(jc, function(x) as.numeric(as.character(x))))

print(jc)

# The following section is the problem.

sem <- function(x){
       sd(x)/sqrt(length(x))
}

meanvalue <- apply(jc,2,mean)
semvalue <- apply(jc, 2, sem)

mean_sem <- data.frame(mean= meanvalue, sem= semvalue, group=names(jc))

#larger font
theme_set(theme_gray(base_size = 20))

#plot using ggplot
p <- ggplot(mean_sem, aes(x=group, y=mean)) +
              geom_line(stat='identity') +
              geom_errorbar(aes(ymin=mean-sem, ymax=mean+sem),
                           width=.2)
print(p)

Thanks,
Mohan
This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored.

	[[alternative HTML version deleted]]



More information about the R-help mailing list