Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205330

How can I generate error bars upper and lower whisker in ggplot2?

$
0
0

I am trying to replicate a box plot using R ggplot. However, I am having difficulties adding error bar especially with upper and lower horizontal lines. Also in my graph the jitter points are spread unevenly. Here is my code and the output

survey <- data.frame(sample=rep(c("sample1","sample1", "sample1", "sample1", "sample1", "sample1", "sample1", "sample1", "sample1", "sample1", "sample2", "sample2", "sample2", "sample2", "sample2", "sample2", "sample2", "sample2", "sample2", "sample2"),1),
                values=c(200, 100, 150, 175, 145, 50, 75, 60, 45, 56, 300, 200, 150, 100, 125,  25, 50, 75, 45, 35))             
survey
library(ggplot2)
p1 <- ggboxplot(survey, x = "sample", y = "values", color = "black", fill = "sample", 
            palette =c("grey", "darkgrey"),
            width = 0.3, add = c("mean_se", "jitter"),
            add.params = list(size = 0.9))
p1

my_output

I would like to generate two different types of boxplots, as presented in these example boxplots. Could anyone help in generating these boxplots. Thank you

Desired_Output_1Desired_Output_2


Viewing all articles
Browse latest Browse all 205330

Trending Articles