user5779223
user5779223

Reputation: 1490

Fail to use boxplot in ggplot2

Given such a data frame:

dt       val
02-09     0.1
02-09     0.2
02-09     0.15
02-10     0.3
02-10     -0.1
...

I want to use the boxplot to show the medium, variance of val in each dt:

 ggplot(data = df,aes(y=val,x=dt)) + geom_boxplot()

But what i got is : enter image description here

It can observed that there is just one box. When I tried outlier.colour = "red", all the points are red. Why? All the values are in the interval of (-1,1)

Upvotes: 1

Views: 113

Answers (1)

Roland
Roland

Reputation: 132989

This should explain the problem:

set.seed(42)
x <- rnorm(10)
x <- c(x, rep(0, 100)) #add 100 zero values
boxplot(x)

resulting plot

quantile(x, c(0.25, 0.5, 0.75))
#25% 50% 75% 
#  0   0   0

If you have many (almost) identical values, the quartiles are (almost) identical.

Upvotes: 5

Related Questions