1

I want to visualize my data using Boxplot.

I have created a boxplot and a stripchar using the follwonig comands:

  adjbox(nkv.murgang$NK, main = "NKV, Murgang - Skewness Adjusted", horizontal = T, axes = F,
           staplewex = 1, xlab = "Nutzen Kosten Verhältnis")

  stripchart(nkv.murgang$NK, main = "NKV, Murgang - Stripchart", horizontal = T, pch = 1,
             method = "jitter", xlab = "Nutzen Kosten Verhältnis")

However I cannot figure out how to incorporate the corresponding five number statistics into the graph (min, 1st Qu., Mean, 3rd Qu., Max). I want them to be display next to the whiskers.

What is my y-axis in this case?

Additionaly, I also want to highlight the mean and median with different colours. Something like this:

desired output

is it possible to combine this two into one graph?

Thanks for any input. I know this seems very basic, but I am stuck here...

Nneka
  • 1,764
  • 2
  • 15
  • 39
  • Your code includes `horizontal = T` but your sample plot is vertical. Which do you want? Also, Do you want the Five Number Stats in the boxplot, the strip chart or both? Your sample code uses `adjbox`. Would you be open to using the base R `boxplot`? – G5W Mar 27 '17 at 14:52
  • 1
    Also, your sample graph seems to be grouped by some factor, but your sample data and code just has one box and one strip. Is that what you intended? – G5W Mar 27 '17 at 14:58
  • Unfortunately your dataset neither has the factor variable visible in the plots, nor has it the color-information. Also you do not disclose from which package the functions `adjbox` and `stripchart` come from. – Rentrop Mar 27 '17 at 15:48
  • You might want to look at the [Previous SO Answer](http://stackoverflow.com/a/41211295/4752675) – G5W Mar 27 '17 at 15:59
  • @ G5W I want a horizotal boxplot, just coudln't find exact example. I would like the Five Number Stats to be displayed only in the boxplot, but the color distinguished mean and median in both. Boxplot instead of adjbox is acceptable. The sample data has just one box and one strip, because i have various datasets (to be exact 4 datasets). From each dataset I only create one boxplot and one strip chart. AT the end I would like to combine them all, so i can compare them – Nneka Mar 28 '17 at 06:32

2 Answers2

1

You can combine a boxplot with a point-plot using ggplot2 as follows

require(ggplot2)
ggplot(mtcars, aes(x = as.factor(gear), y = wt)) + 
  geom_boxplot() +
  geom_jitter(aes(col = (cyl == 4)), width = 0.1)

The result would be:

enter image description here

Rentrop
  • 20,979
  • 10
  • 72
  • 100
1

Instead of using adjbox, use ggplot:

There is a trick for the unknown x-axis: x = factor(0).

  ggplot(nkv.murgang, aes(x = factor(0), nkv.murgang$NK)) +
    geom_boxplot(notch = F, outlier.color = "darkgrey", outlier.shape = 1,
                 color = "black", fill = "darkorange", varwidth = T) + 
    ggtitle("NKV Murgang - Einfamilienhaus") + 
    labs(x = "Murgang", y = "Nutzen / Konsten \n Verhälhniss") +
    stat_summary(geom = "text", fun.y = quantile,
                 aes(label=sprintf("%1.1f", ..y..)),
                 position=position_nudge(x=0.4), size=3.5)

enter image description here

This question explains.

Community
  • 1
  • 1
Nneka
  • 1,764
  • 2
  • 15
  • 39