我想以更清晰的方式重新绘制下图。观察我正在尝试绘制线条和点。但是,正在打印的点数太多了,线条被掩盖了。有没有一种方法,我可以积:如何绘制线条和点数有限的点?
- 不同的线不同的数据集
- 的不同点为形状不同的数据集,但限制的点数说30-50
- 添加线和点信息到传说
我的绘制代码here(这是太大SO)
我想以更清晰的方式重新绘制下图。观察我正在尝试绘制线条和点。但是,正在打印的点数太多了,线条被掩盖了。有没有一种方法,我可以积:如何绘制线条和点数有限的点?
我的绘制代码here(这是太大SO)
你需要这样的东西吗?
transData$Type2 <- factor(transData$Type, labels = c("Some Info for P", "Some Info for Q"))
ggplot(transData, aes(x=Value, y=ecd)) +
geom_line(aes(group=Type2,colour=Type2, linetype=Type2), size=1.5) +
geom_point(aes(shape = Type2), data = transData[round(seq(1, nrow(transData), length = 30)), ], size = 5) +
opts(legend.position = "top", legend.key.width = unit(3, "line"))
您可以绘制大的,部分透明的点:密度更大的区域会显得更暗。
p <- ggplot(transData, aes(x=Value, y=ecd, group=Type))
p +
geom_point(size=20, colour=rgb(0,0,0,.02)) +
geom_line(aes(colour=Type), size=3)
下面的代码添加点或多或少均匀分布的,虽然他们不一定实际数据点(可插值),
barbedize <- function(x, y, N=10, ...){
ind <- order(x)
x <- x[ind]
y <- y[ind]
lengths <- c(0, sqrt(diff(x)^2 + diff(y)^2))
l <- cumsum(lengths)
tl <- l[length(l)]
el <- seq(0, to=tl, length=N+1)[-1]
res <-
sapply(el[-length(el)], function(ii){
int <- findInterval(ii, l)
xx <- x[int:(int+1)]
yy <- y[int:(int+1)]
dx <- diff(xx)
dy <- diff(yy)
new.length <- ii - l[int]
segment.length <- lengths[int+1]
ratio <- new.length/segment.length
xend <- x[int] + ratio * dx
yend <- y[int] + ratio * dy
c(x=xend, y=yend)
})
as.data.frame(t(res))
}
library(plyr)
few_points <- ddply(transData, "Type", function(d, ...)
barbedize(d$Value, d$ecd, ...), N=10)
ggplot(transData, aes(x=Value, y=ecd)) +
geom_line(aes(group=Type,colour=Type, linetype=Type), size=1) +
geom_point(aes(x=x,y=y, colour=Type, shape=Type), data=few_points, size=3)
(这是一个快速和肮脏的原理证明,barbedize
应该被清理和更有效地写入...)
这个问题让我想起了从['barbedGrob'](http://code.google.com/p/gridextra/wiki/barbedGrob)制作'ggplot2' geom的回避计划。我想知道,当它们非常接近时,也可以选择只画几点,如上所述。 – baptiste
如果情节是一个经验累积分布函数(ECDF),作为轴顾名思义,不存在在图的左下角的竖直段的(有一个在右上,对于其它基团),并且对应于许多“0”或“1”值的两个垂直段(左下角和左上角)没有点,看起来很奇怪(我希望“ecd”列在[0, 1])。 –