1

数据文件:http ://ubuntuone.com/3x5z4kFEUcVUB8KXYjICpD

像这样绘制上面的数据会剪辑其中的一些:

tc = read.table('tertiary-tc.csv', header=T, sep=',')
library(ggplot2)
old <- theme_set(theme_bw())
pg <- ggplot(tertiary, aes(Conductivity)) + stat_density(geom = 'path'
    , position = 'identity') + facet_wrap(~Lithology)
print(pg)

而这不是:

library(lattice) 
densityplot(~Conductivity | Lithology
    , data = tc
    , groups=Lithology
    , plot.points=T
    , ref = T
    , main="Density plot"
    , auto.key=F
    , scales=list(tck=-1))  # set to a negative to plot inside ticks? Works!
dev.off()

未绘制的点(只是快速查看)是在“岩性”列下归类为“白云石”的两个点。ggplot2 是否因为它们超出比例而没有绘制它们?还是因为只有两点?

4

1 回答 1

2

这样的事情可能会让你开始

density2 <- function(x, select, ...){
  n <- nrow(x)
  range <- range(x[[select]])
  xgrid <- seq(range[1], range[2], length=200)

  weight <- rep(1, n) / n
  d <- density(x[[select]], ...,
                  weight=weight, from=range[1], to=range[2])

  as.data.frame(d[c("x","y")])

}


summaries <- ddply(tc, "Lithology", density2, select="Conductivity")

 ggplot(summaries, aes(x, y))  + facet_wrap(~Lithology) +
  geom_path()

不知道为什么它看起来以某种方式修剪,我不熟悉density()

于 2012-04-12T08:11:02.430 回答