2017-01-16 10 views
2

グリッドを使ってプロットする方法を学んだが、Rスタジオはbookの例とは異なる結果を示した。だから私はRで同じコードを実行し、本の例と同じ結果を得ました。この理由は分かりません...RとRスタジオで同じコードが異なる動作

以下はコードです。

library(grid) 
grid.newpage() 
pushViewport(plotViewport(c(5, 4, 2, 2))) 
pushViewport(dataViewport(pressure$temperature,pressure$pressure,name="plotRegion")) 
grid.points(pressure$temperature, pressure$pressure,name="dataSymbols") 
grid.rect() 
grid.xaxis() 
grid.yaxis() 
grid.text("temperature", y=unit(-3, "lines")) 
grid.text("pressure", x=unit(-3, "lines"), rot=90) 
grid.edit("dataSymbols", pch=2) 
upViewport(2) 
grid.rect(gp=gpar(lty="dashed")) 
downViewport("plotRegion") 
grid.text("Pressure (mm Hg)\nversus\nTemperature (Celsius)",x=unit(150, "native"), y=unit(600, "native")) 

Rスタジオ

enter image description here

R

enter image description here

+1

ファイルに出力してみてください? – zx8754

+0

これを再現できるようにいくつかのデータを共有することはできますか? –

+0

@RomanLuštrik完全に再現可能です。 「圧力」はデータセットパッケージに含まれています。 – Roland

答えて

3

このコードは、gparで定義されたデフォルト値を使用します。ヘルプは言う:

デフォルトのパラメータ設定が は、グラフィックスデバイスからその設定を取るROOTビューポートによって定義されています。これらのデフォルト値はデバイス間で で異なる場合があります(たとえば、PDFデバイスと比較してPNG デバイスのデフォルトの埋め込み設定が異なります)。 RGuiで

get.gpar()$fill 
#[1] "white" 

:RStudioと

get.gpar()$fill 
#[1] "transparent" 

したがって、RStudio装置は異なる設定を有しています。四角形を塗り潰さないように明示的に指定する必要があります。

library(grid) 
grid.newpage() 
pushViewport(plotViewport(c(5, 4, 2, 2))) 
pushViewport(dataViewport(pressure$temperature,pressure$pressure,name="plotRegion")) 
grid.points(pressure$temperature, pressure$pressure,name="dataSymbols") 
grid.rect(gp = gpar(fill = NA)) 
grid.xaxis() 
grid.yaxis() 
grid.text("temperature", y=unit(-3, "lines")) 
grid.text("pressure", x=unit(-3, "lines"), rot=90) 
grid.edit("dataSymbols", pch=2) 
upViewport(2) 
grid.rect(gp=gpar(lty="dashed", fill = NA)) 
downViewport("plotRegion") 
grid.text("Pressure (mm Hg)\nversus\nTemperature (Celsius)",x=unit(150, "native"), y=unit(600, "native")) 

resulting plot

関連する問題