Quantcast
Channel: singular point » StatGraphic
Viewing all articles
Browse latest Browse all 11

image.plot の目盛を axis 関数で描く

$
0
0

Rのfieldsパッケージのimage.plot関数で目盛に数値ではなくテキストを書き込みたい。axis関数を使っても何故か反映されないというバグ?がある(fieldsのバージョンは6.9.1)。例えば以下の例:

library(fields)

x <- matrix(rnorm(25),nc=5)

colnames <- paste0("col",1:5)
rownames <- paste0("raw",1:5)

# Fail
image.plot(1:5, 1:5, x, xaxt="n", yaxt="n", xlab="X-axis", ylab="Y-axis")
axis(side=2,at=1:5,labels=rownames)
axis(side=1,at=1:5,labels=colnames)

image_plot_fail

確かに最後の二行の axis 関数の結果が反映されていない(x軸, y軸の目盛に文字が書けていない)。

r- how to edit elements on x axis in image.plot
この問題はここでも議論されていて、普通のimageを使って、凡例だけimage.plotを使え、とある。

もう少し簡単に解決する方法を見つけた。

# Success
image.plot(1:5, 1:5, x, xaxt="n", yaxt="n", xlab="X-axis", ylab="Y-axis")
text(-100,-100,".")  # This is dummy, but required for drawing axis
axis(side=2,at=1:5,labels=rownames)
axis(side=1,at=1:5,labels=colnames)

image.plot と axis の間にダミーでtext関数を実行する(三行目)。以下のとおり不思議なことにこれで解決した(理由は未調査)。

image_plot_success


Viewing all articles
Browse latest Browse all 11

Latest Images

Trending Articles





Latest Images