2012-06-05 56 views
4

我用切断密度图中GGPLOT2

frame <- read.table(paste('data', fname, sep="/"), sep=",", header=TRUE) 
colnames(frame) <- c("pos", "word.length") 
plot <- ggplot(frame, aes(x=pos, y=word.length)) + xlim(0,20) + ylim(0,20) + geom_density2d() + stat_density2d(aes(color=..level..)) 
png(paste("graphs/", fname, ".png", sep=""), width=600, height=600) 
print(plot) 
dev.off() 

创造情节,但它们会被截断。我该如何解决?

http://ompldr.org/vZTN0eQ

我用于创建此图中的数据:http://sprunge.us/gKiL

+0

如果我构成一些范围从0到20的数据,我的情节看起来不错。也许你可以提供一些复制问题的数据?如果您省略'xlim'和'ylim'选项,ggplot会根据您的数据限制为您选择它们​​。我怀疑这是你的问题所在。 – Justin

+0

你是对的,但我有不同的数据集,有些在3到10的范围内,其他的全是0到20的范围,我希望他们可以比较。显然'lim's没有正确传递。 – Reactormonk

+0

限制通过与您通过它们的时间一样,0:20。所以从3:10开始的数据看起来是“切断”的,因为它们不会延伸到图的边缘。同样,如果您提供一些数据,您可以得到更好的答案。我建议将数据放入一个data.frame中,并用'facet_wrap'或'facet_grid'绘制并修改您的比例。这样所有的地块都有一个比例。 – Justin

回答

3

按照GGPLOT2书,您使用scale_x_continuous(limits=c(1,20)),而不是xlim(1,20)了点。