I am attempting to plot a boxplot where my x-axis is a continuous time-scale which is growing degree days i.e. 0 to 2500. I would like to get a boxplot with x-axis values correctly spaced on a continuous time-scale rather than a discrete one. Normally if it were a regular time/date, I could have used a 'scale_x_date' with ggplot2 in R. However, since the numbers are outside date/time scale I am not sure how can we correctly space the x-axis values. Here is the dummy example:
library(ggplot2)
set.seed(1234)
#get data
df <- data.frame(y=abs(rnorm(8)),
x=as.factor(rep(c(0,100,200,500),times=2)))
ggplot(aes(y=y,x=x), data=df) +
geom_boxplot()
This gives me the plot
where my x-axis is not spaced based on its numeric values. Instead, I would like to get a boxplot where the spacing between 200 to 500 should be three times more than 100-200. My actual data has x-axis values ranging 0-2500 growing days. I am looking for ggplot2 specific solution preferably.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…