-1

enter image description here

below code which i used for making boxlplot but i can't change some parts of whiskeres so please notice to me how to change. i attached png.

ggplot(data =data,aes(x = Voting.Method, y = Accuracy))+
stat_boxplot(geom ='errorbar',width=0.15) +
geom_boxplot(fill="white", fatten = 0, size=1, width=0.3)+
stat_summary(fun = mean, geom = "errorbar", aes(ymax = ..y.., ymin = ..y.., color = "mean"),
                 width = .3, linetype = 1,size=1) +
stat_summary(fun = median, geom = "errorbar", aes(ymax = ..y.., ymin = ..y.., color = "median"),
                 width = .3, linetype = 1,size=1) +
theme(legend.title=element_blank(), legend.text = element_text(size=15, face="bold"), legend.background = element_rect(color="black"),
legend.position =c(0.9,0.9),legend.direction = "vertical", axis.text.x = element_text(size=15, angle = 20,vjust=0.5),
axis.text.y = element_text(size =15),axis.title.y = element_text(size =20),axis.title.x=element_blank()) +
scale_y_continuous(limits = c(50, 75)) +
scale_color_manual(values=c("skyblue","lightgreen"))+
scale_x_discrete(limits=c("LSTM","Bi-LSTM","GRU","Bi-GRU"))
box+ylab("Accuracy(%)")
HYUN K
  • 9
  • Please share your data using `dput(df)`? – Quinten Jun 01 '22 at 08:57
  • Perhaps this question might help (TL;DR: draw boxplot twice): https://stackoverflow.com/questions/29372200/how-to-customize-whisker-lines-on-a-geom-box-plot-differently-than-the-lines-of – Dmitry Zotikov Jun 01 '22 at 09:07
  • Hyun, you asked the same question earlier this morning and i had already closed this as a duplicate. It's really not good style to ask the same question again and not referring to the first one. You actually seem to have deleted this first question. This is also no necessary. Duplicates are good, please ideally leave them for future queries – tjebo Jun 01 '22 at 10:37
  • if you don't think this helps, then instead of asking the question again, without reference to the first one, please explain why this doesn't help you – tjebo Jun 01 '22 at 10:38

1 Answers1

2

The 'simple' way would be to draw the boxplot and the errorbars with seperate linetypes e.g. (using the palmerpenguins dataset):

library(tidyverse)
library(palmerpenguins)

penguins %>%
  ggplot(aes(x = species, y = body_mass_g)) +
  stat_boxplot(geom = "errorbar", width = 0.3, lty = 2) +
  geom_boxplot(aes(ymin=..lower.., ymax=..upper..)) +
  stat_summary(fun = mean, geom = "errorbar", aes(ymax = after_stat(y), ymin = after_stat(y), color = "mean"),
               width = .75, linetype = 1, size=1) +
  stat_summary(fun = median, geom = "errorbar", aes(ymax = after_stat(y), ymin = after_stat(y), color = "median"),
               width = .75, linetype = 1, size=1) +
  theme_minimal() +
  scale_y_continuous(limits = c(0, 8000)) +
  theme(legend.title=element_blank(), 
        legend.text = element_text(size=15, face="bold"), 
        legend.background = element_rect(color="black"),
        legend.position =c(0.9,0.9),
        legend.direction = "vertical", 
        axis.text.x = element_text(size=15, angle = 20, vjust=0.5),
        axis.text.y = element_text(size =15),
        axis.title.y = element_text(size =20),
        axis.title.x=element_blank())

Created on 2022-06-01 by the reprex package (v2.0.1)

The 'more complicated' way would be to draw in the caps yourself, e.g.

library(tidyverse)
library(palmerpenguins)

penguins %>%
  na.omit() %>%
  group_by(species) %>%
  mutate(bottom_cap = boxplot.stats(body_mass_g)$stats[1],
         top_cap = boxplot.stats(body_mass_g)$stats[5]) %>%
  ggplot(aes(x = species, y = body_mass_g)) +
  stat_boxplot(geom = "errorbar", width = 0.3, lty = 2) +
  geom_linerange(aes(xmin = as.numeric(species) - 0.2,
                     xmax = as.numeric(species) + 0.2,
                     y = top_cap)) +
  geom_linerange(aes(xmin = as.numeric(species) - 0.2,
                     xmax = as.numeric(species) + 0.2,
                     y = bottom_cap)) +
  geom_boxplot(aes(ymin=..lower.., ymax=..upper..)) +
  stat_summary(fun = mean, geom = "errorbar", aes(ymax = after_stat(y), ymin = after_stat(y), color = "mean"),
               width = .75, linetype = 1, size=1) +
  stat_summary(fun = median, geom = "errorbar", aes(ymax = after_stat(y), ymin = after_stat(y), color = "median"),
               width = .75, linetype = 1, size=1) +
  theme_minimal() +
  scale_y_continuous(limits = c(0, 8000)) +
  theme(legend.title=element_blank(), 
        legend.text = element_text(size=15, face="bold"), 
        legend.background = element_rect(color="black"),
        legend.position =c(0.9,0.9),
        legend.direction = "vertical", 
        axis.text.x = element_text(size=15, angle = 20, vjust=0.5),
        axis.text.y = element_text(size =15),
        axis.title.y = element_text(size =20),
        axis.title.x=element_blank())

Created on 2022-06-01 by the reprex package (v2.0.1)

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46