1

I am using the following in R to generate a Boxplot out of a given set of data:

ggplot(data = daten, aes(x=Bodentyp, y=Fracht)) + geom_boxplot(aes(fill=Bewirtschaftungsform))

Now I want to display the number of data points going into each category of the column "Bodentyp". How do I achieve this?

1
  • I'm not quite sure what you exactly want to have (perhaps some data and/or the expected (visual) output would help), but does adding geom_jitter(aes(colour = Bewirtschaftungsform)) do what you like to have? Commented Jun 30, 2015 at 13:34

1 Answer 1

4

You can use fun.datato apply a function (f) to the grouped data to return a count (length(y)) and a position for the label (median(y))

f <- function(y) 
    c(label=length(y), y=median(y))

library(ggplot2)
data(mtcars)
ggplot(mtcars, aes(x=as.factor(cyl), y=mpg)) +
  geom_boxplot() + theme_bw() +
  stat_summary(fun.data=f, geom="text", vjust=-0.5, col="blue")

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.