在成千上万的数据集中,我的程序偶尔会遇到那些只包含相同值的数据集,为此我需要 ggplot2 绘制与base R 相同的图:只需将中值绘制为正确值即可。ggplot2 有没有办法做到这一点?
dput(df)
structure(list(station = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L), .Label = "x", class = "factor"), value = c(1e-04,
1e-04, 1e-04, 1e-04, 1e-04, 1e-04, 1e-04, 1e-04, 1e-04, 1e-04
)), .Names = c("station", "value"), class = "data.frame", row.names = c(NA,
-10L))
station value
x 1.00E-04
x 1.00E-04
x 1.00E-04
x 1.00E-04
x 1.00E-04
x 1.00E-04
x 1.00E-04
x 1.00E-04
x 1.00E-04
x 1.00E-04
# via base R:
boxplot(df$value ~ df$station,
main="base R: correct median, \ncorrect data range")
# via ggplot2:
library(ggplot2)
ggplot(df, aes(factor(df$station), df$value)) +
geom_boxplot() +
ggtitle("ggplot2: incorrect median, \nincorrect data range")