2012-01-26 31 views
0

我想以更清晰的方式重新绘制下图。观察我正在尝试绘制线条和点。但是,正在打印的点数太多了,线条被掩盖了。有没有一种方法,我可以积:如何绘制线条和点数有限的点?

  • 不同的线不同的数据集
  • 的不同点为形状不同的数据集,但限制的点数说30-50
  • 添加线和点信息到传说

enter image description here

我的绘制代码here(这是太大SO)

+0

如果情节是一个经验累积分布函数(ECDF),作为轴顾名思义,不存在在图的左下角的竖直段的(有一个在右上,对于其它基团),并且对应于许多“0”或“1”值的两个垂直段(左下角和左上角)没有点,看起来很奇怪(我希望“ecd”列在[0, 1])。 –

回答

2

你需要这样的东西吗?

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")) 

enter image description here

+0

是的......完美!差不多了。有没有办法将统一点也统一起来? – Legend

+0

我想你可以适应[此过程](http://stackoverflow.com/a/6904434/471093)定期绘制点。 – baptiste

1

您可以绘制大的,部分透明的点:密度更大的区域会显得更暗。

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) 
+0

谢谢。这看起来很棒,但由于透明度的原因,我不确定这款产品是否符合EPS标准?另外,我需要一个点图例,以便在使用BW打印机打印图形时,它仍然清晰易读。 – Legend

+0

PostScript(eps)没有透明度 - 我认为在过去的十年中,这种格式已被pdf完全替代... –

+0

+1。不幸的是,在学术界,我们仍然使用EPS有一些奇怪的原因。不过谢谢你的帮助。 – Legend

0

下面的代码添加点或多或少均匀分布的,虽然他们不一定实际数据点(可插值),

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) 

shape

(这是一个快速和肮脏的原理证明,barbedize应该被清理和更有效地写入...)

+0

这个问题让我想起了从['barbedGrob'](http://code.google.com/p/gridextra/wiki/barbedGrob)制作'ggplot2' geom的回避计划。我想知道,当它们非常接近时,也可以选择只画几点,如上所述。 – baptiste

相关问题