1

これが発生する形式であるため、ポイントのペアをプロットしようとしています。このデータは、商用部品 (電子部品) について説明しており、その動作は 2 つの周波数の間で変動します。これはデータセットの小さな例です:

freq1  freq2  gain  
2.0    6.0    43
6.0   18.0    40
8.5   10.5    50 
8.5    9.3    52

データはさまざまな周波数で表示されるため、これを 2 つの点を結ぶ線として表示したいと思います。たとえば、最初の行は (2, 43) と (6, 43) の 2 つの点を記述しています。

別の可能性は、中心周波数を計算し、そこにポイントを配置し、各ポイントで描画する画像の幅を計算して、 と の範囲になるようにすることfreq1ですfreq2。これにより、コードを書き始めることができないほど多くの疑問が生じます。

だから、私の質問は次のとおりです。gain結合する線に対して各値をプロットできますか(できればggplot2を使用して)freq1freq2

4

3 に答える 3

9

推測ですlatticeExtraが、興味深いsegplotものがあります(拡張ドットプロットです)

ここに画像の説明を入力

いくつかのデータの読み取り:

  dat <- read.table(text ='freq1  freq2  gain  
2.0    6.0    43.
6.0   18.0    40.
8.5   10.5    50. 
8.5    9.3    52.',head=T)

dat$compo <- paste('compo',1:nrow(dat),sep='')
library(latticeExtra)
segplot(reorder(factor(compo), gain)~freq1+freq2,
        data=dat,draw.bands=FALSE,centers=gain,
        segments.fun = panel.arrows,ends = "both", 
        angle = 90, length = 1, scales=list(y=list(cex=1.5)),
        unit = "mm",
        main = ' Range frequencies'  ,sub= 'electronic components', 
        ## a serious theme here :)
        par.settings = theEconomist.theme(with.bg = TRUE))

EDITいくつかの写真を追加

library(png)

ll <- list.files(path=path_picts,patt='compo[0-9].*',full.names=T)
imgs <- lapply(ll,readPNG)
#ll <- gsub('.*(compo[0-9]).png','\\1',ll)
#names(imgs) <- ll
dat$compo <- paste('compo',1:nrow(dat),sep='')
segplot(factor(compo)~freq1+freq2,
        data=dat,draw.bands=FALSE,centers=gain,
        segments.fun = panel.arrows,ends = "both", 
        angle = 90, length = 1, scales=list(y=list(cex=1.5)),
        unit = "mm",
        main = ' Range frequencies'  ,sub= 'electronic components',
        par.settings = ggplot2like(),axis = axis.grid,

        panel = function(x,y,...){
            panel.segplot(x,y,...)
            browser()
            lapply(seq_along(ll),function(img){
                 x1 <- x[img];y1 <- y[img];
                  grid.raster(image=imgs[[img]],x=(x1+y1)*0.5,y=img,width=y1-x1, height=0.5,interpolate=F,
                        default.units = 'native')})

        })

ここに画像の説明を入力

于 2013-03-04T20:59:44.020 に答える
8

これがあなたの質問への答えです

> dat
  freq1 freq2 gain
1   2.0   6.0   43
2   6.0  18.0   40
3   8.5  10.5   50
4   8.5   9.3   52

> attach(dat)

#Don't actually need to calculate the midpoint but since you suggested it
#that's the way I did it
midpoint = (freq1+freq2)/2
plot(midpoint,gain,xlim=c(min(freq1),max(freq2)),col="white",xlab="")

points(freq1,gain,col=1:length(gain),pch=19)
points(freq2,gain,col=1:length(gain),pch=19)

for(i in 1:length(gain)){
    lines(c(freq1[i],freq2[i]),c(gain[i],gain[i]),col=i)
}

ここに画像の説明を入力

于 2013-03-04T20:54:59.647 に答える
5

価値のあるものとして、ここに のアイデアがありggplot2ます。多かれ少なかれすべてを備えていますが、その上に何でも構築できます。

ggplot(data = df, aes(x=freq1, y=gain)) + 
      geom_segment(aes(xend=freq2, yend=gain, colour=factor(1:4)))

ここに画像の説明を入力

于 2013-03-04T21:40:12.807 に答える