グラフィックス参考実例集:ラティスグラフィックス
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
COLOR(red){SIZE(20){グラフィックス参考実例集:ラティスグ...
([[グラフィックス参考実例集]]に戻る。[[Rのグラフィックス...
アドオンパッケージ COLOR(red){lattice} は S 用に開発され...
#contents
~
//*オブジェクト一覧
//
//| オブジェクト名 | 説明 ...
//| banking | Banking ...
//| cloud | 3d Scatter Plot ...
//| draw.colorkey | Produce a Colorkey for leve...
//| draw.key | Produce a Legend or Key|
//| histogram | Histograms and Kernel Densi...
//| latticeParseFormula | Parse Trellis formula|
//| Lattice | Lattice Graphics|
//| levelplot | Level Plots|
//| llines | Lattice Replacements of bas...
//| lset | Simple Interfaces to modify...
//| oneway | Fit One-way Model|
//| panel.barchart | Default Panel Function for ...
//| panel.bwplot | Default Panel Function for ...
//| panel.cloud | Default Panel Function for ...
//| panel.densityplot | Default Panel Function for ...
//| panel.dotplot | Default Panel Function for ...
//| panel.functions | Useful Panel Functions|
//| panel.histogram | Default Panel Function for ...
//| panel.levelplot | Default Panel Function for ...
//| panel.pairs | Default Superpanel Function...
//| panel.parallel | Default Panel Function for ...
//| panel.qqmathline | Useful panel function with ...
//| panel.stripplot | Default Panel Function for ...
//| panel.superpose | Panel Function for Display ...
//| panel.tmd | Panel function for tmd|
//| panel.xyplot | Default Panel Function for ...
//| prepanel.functions | Useful Prepanel Function fo...
//| print.trellis | Print Trellis Objects|
//| qqmath | Q-Q Plot with Theoretical D...
//| qq | Quantile-Quantile Plots of ...
//| rfs | Residual and Fit Spread Plo...
//| Rows | Extract 'rows' from a list|
//| shingles | shingles|
//| simpleKey | Function to generate a simp...
//| splom | Scatter Plot Matrices|
//| strip.default | Default Trellis strip function|
//| tmd | Tukey Mean-Difference Plot|
//| trellis.datasets | Data Sets in the Lattice li...
//| trellis.device | Initializing Trellis Displa...
//| trellis.object | Lattice Display Object |
//| trellis.par.get | Graphical Parameters for Tr...
//| update.trellis | Update Trellis Object |
//| xyplot | Common Bivariate Trellis Pl...
*COLOR(red){wireframe} 関数
wireframe1 <- function() {
library(lattice)
x <- seq(-pi, pi, len = 20)
y <- seq(-pi, pi, len = 20)
g <- expand.grid(x = x, y = y)
g$z <- sin(sqrt(g$x^2 + g$y^2))
wireframe(z ~ x * y, g, drape = TRUE,
perspective = FALSE,
aspect = c(3,1), colorkey = FALSE)
pp <- recordPlot(); png("lattice.wireframe1.png"); re...
}
#ref(lattice.wireframe1.png,left)
wireframe2 <- function() {
library(lattice)
g <- expand.grid(x = 1:10, y = 5:15, gr = 1:2)
g$z <- log((g$x^g$g + g$y^2) * g$gr)
wireframe(z ~ x * y, data = g, groups = gr,
scales = list(arrows = FALSE),
shade = TRUE,
shade.colors = function(cosangle, height)
palette.shade(cosangle, height = .15, satura...
light.source = c(0, 0, 1),
screen = list(z = 30, x = -60))
pp <- recordPlot(); png("lattice.wireframe2.png"); re...
}
#ref(lattice.wireframe2.png,left)
*COLOR(red){cloud} 関数(三次元散布図)
cloud1 <- function() {
library(lattice)
data(iris)
cloud(Sepal.Length ~ Petal.Length * Petal.Width, data ...
groups = Species, screen = list(x = -90, y = 70),
aspect = c(1, 1), distance = .4, zoom = .6,
key = list(title = "Iris Data", x = .1, y=.9,
corner = c(0,1),
border = TRUE,
points = Rows(trellis.par.get("superpose.symbo...
text = list(levels(iris$Species))))
pp <- recordPlot(); png("lattice.cloud1.png"); replay...
}
#ref(lattice.cloud1.png,left)
*COLOR(red){histogram} 関数
histogram1 <- function() {
library(lattice)
data(singer)
histogram( ~ height | voice.part, data = singer, nint ...
endpoints = c(59.5, 76.5), layout = c(2,4), ...
xlab = "Height (inches)")
pp <- recordPlot(); png("lattice.histogram1.png"); re...
}
#ref(lattice.histogram1.png,left)
## この例は S-Plus では表示できないかも知れない
histogram2 <- function() {
library(lattice)
data(singer)
histogram( ~ height | voice.part, data = singer,
xlab = "Height (inches)", type = "density",
panel = function(x, ...) {
panel.histogram(x, ...)
panel.mathdensity(dmath = dnorm,
args = list(mean=mean(x)...
} )
pp <- recordPlot(); png("lattice.histogram2.png"); rep...
}
#ref(lattice.histogram2.png,left)
*COLOR(red){densityplot} 関数
densityplot3 <- function() {
library(lattice)
data(singer)
densityplot( ~ height | voice.part, data = singer, lay...
xlab = "Height (inches)", bw = 5)
pp <- recordPlot(); png("lattice.densityplot1.png"); r...
}
#ref(lattice.histogram3.png,left)
*COLOR(red){levelplot} 関数
levelplot1 <- function() {
library(lattice)
x <- seq(pi/4, 5*pi, length = 100)
y <- seq(pi/4, 5*pi, length = 100)
r <- as.vector(sqrt(outer(x^2, y^2, "+")))
grid <- expand.grid(x=x, y=y)
grid$z <- cos(r^2) * exp(-r/(pi^3))
levelplot(z~x*y, grid, cuts = 50, xlab="", ylab="",
main="Weird Function", colorkey = FALSE)
}
#ref(lattice.levelplot1.png,left)
*COLOR(red){contourplot} 関数
contourplot1 <- function() { #S+ example
library(modreg)
library(lattice)
data(environmental)
attach(environmental)
ozo.m <- loess((ozone^(1/3)) ~ wind * temperature * ra...
parametric = c("radiation", "wind"), sp...
w.marginal <- seq(min(wind), max(wind), length = 50)
t.marginal <- seq(min(temperature), max(temperature), ...
r.marginal <- seq(min(radiation), max(radiation), leng...
wtr.marginal <- list(wind = w.marginal, temperature = ...
radiation = r.marginal)
grid <- expand.grid(wtr.marginal)
grid[, "fit"] <- c(predict(ozo.m, grid))
contourplot(fit ~ wind * temperature | radiation, data...
cuts = 10, region = TRUE,
xlab = "Wind Speed (mph)",
ylab = "Temperature (F)",
main = "Cube Root Ozone (cube root ppb)",
col.regions = trellis.par.get("regions")$c...
detach()
}
#ref(lattice.contourplot1.png,left)
*グラフの回転 r-help 記事より
> library(lattice)
> library(grid)
> myhist <- histogram(rnorm(50))
> # Make two square regions side by side
> push.viewport(viewport(layout=grid.layout(1, 2, respec...
> # Go to the left region
> push.viewport(viewport(layout.pos.col=1))
> # Draw the histogram in normal orientation
> print(myhist, newpage=FALSE)
> pop.viewport()
> # Go to the right region then rotate 90 degrees
> push.viewport(viewport(layout.pos.col=2), viewport(ang...
> # Draw the histogram (rotated 90 degrees)
> print(myhist, newpage=FALSE
> pop.viewport(3)
#ref(rotate.graph.png, left)
* P. Murrel の gridBase パッケージによるグラフィックス例 ...
gridBase.ex.1 <- function() {
#library(grid)
library(gridBase)
#library(lattice)
midpts <- barplot(1:10, axes=FALSE)
axis(2)
axis(1, at=midpts, labels=FALSE)
vps <- baseViewports()
par(new=TRUE)
push.viewport(vps$inner, vps$figure, vps$plot)
grid.text(c("0ne", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten"),
x = unit(midpts, "native"),
y = unit(-1, "lines"),
just = "right",
rot = 60)
pop.viewport(3)
}
#ref(gridBase1.png,left)
終了行:
COLOR(red){SIZE(20){グラフィックス参考実例集:ラティスグ...
([[グラフィックス参考実例集]]に戻る。[[Rのグラフィックス...
アドオンパッケージ COLOR(red){lattice} は S 用に開発され...
#contents
~
//*オブジェクト一覧
//
//| オブジェクト名 | 説明 ...
//| banking | Banking ...
//| cloud | 3d Scatter Plot ...
//| draw.colorkey | Produce a Colorkey for leve...
//| draw.key | Produce a Legend or Key|
//| histogram | Histograms and Kernel Densi...
//| latticeParseFormula | Parse Trellis formula|
//| Lattice | Lattice Graphics|
//| levelplot | Level Plots|
//| llines | Lattice Replacements of bas...
//| lset | Simple Interfaces to modify...
//| oneway | Fit One-way Model|
//| panel.barchart | Default Panel Function for ...
//| panel.bwplot | Default Panel Function for ...
//| panel.cloud | Default Panel Function for ...
//| panel.densityplot | Default Panel Function for ...
//| panel.dotplot | Default Panel Function for ...
//| panel.functions | Useful Panel Functions|
//| panel.histogram | Default Panel Function for ...
//| panel.levelplot | Default Panel Function for ...
//| panel.pairs | Default Superpanel Function...
//| panel.parallel | Default Panel Function for ...
//| panel.qqmathline | Useful panel function with ...
//| panel.stripplot | Default Panel Function for ...
//| panel.superpose | Panel Function for Display ...
//| panel.tmd | Panel function for tmd|
//| panel.xyplot | Default Panel Function for ...
//| prepanel.functions | Useful Prepanel Function fo...
//| print.trellis | Print Trellis Objects|
//| qqmath | Q-Q Plot with Theoretical D...
//| qq | Quantile-Quantile Plots of ...
//| rfs | Residual and Fit Spread Plo...
//| Rows | Extract 'rows' from a list|
//| shingles | shingles|
//| simpleKey | Function to generate a simp...
//| splom | Scatter Plot Matrices|
//| strip.default | Default Trellis strip function|
//| tmd | Tukey Mean-Difference Plot|
//| trellis.datasets | Data Sets in the Lattice li...
//| trellis.device | Initializing Trellis Displa...
//| trellis.object | Lattice Display Object |
//| trellis.par.get | Graphical Parameters for Tr...
//| update.trellis | Update Trellis Object |
//| xyplot | Common Bivariate Trellis Pl...
*COLOR(red){wireframe} 関数
wireframe1 <- function() {
library(lattice)
x <- seq(-pi, pi, len = 20)
y <- seq(-pi, pi, len = 20)
g <- expand.grid(x = x, y = y)
g$z <- sin(sqrt(g$x^2 + g$y^2))
wireframe(z ~ x * y, g, drape = TRUE,
perspective = FALSE,
aspect = c(3,1), colorkey = FALSE)
pp <- recordPlot(); png("lattice.wireframe1.png"); re...
}
#ref(lattice.wireframe1.png,left)
wireframe2 <- function() {
library(lattice)
g <- expand.grid(x = 1:10, y = 5:15, gr = 1:2)
g$z <- log((g$x^g$g + g$y^2) * g$gr)
wireframe(z ~ x * y, data = g, groups = gr,
scales = list(arrows = FALSE),
shade = TRUE,
shade.colors = function(cosangle, height)
palette.shade(cosangle, height = .15, satura...
light.source = c(0, 0, 1),
screen = list(z = 30, x = -60))
pp <- recordPlot(); png("lattice.wireframe2.png"); re...
}
#ref(lattice.wireframe2.png,left)
*COLOR(red){cloud} 関数(三次元散布図)
cloud1 <- function() {
library(lattice)
data(iris)
cloud(Sepal.Length ~ Petal.Length * Petal.Width, data ...
groups = Species, screen = list(x = -90, y = 70),
aspect = c(1, 1), distance = .4, zoom = .6,
key = list(title = "Iris Data", x = .1, y=.9,
corner = c(0,1),
border = TRUE,
points = Rows(trellis.par.get("superpose.symbo...
text = list(levels(iris$Species))))
pp <- recordPlot(); png("lattice.cloud1.png"); replay...
}
#ref(lattice.cloud1.png,left)
*COLOR(red){histogram} 関数
histogram1 <- function() {
library(lattice)
data(singer)
histogram( ~ height | voice.part, data = singer, nint ...
endpoints = c(59.5, 76.5), layout = c(2,4), ...
xlab = "Height (inches)")
pp <- recordPlot(); png("lattice.histogram1.png"); re...
}
#ref(lattice.histogram1.png,left)
## この例は S-Plus では表示できないかも知れない
histogram2 <- function() {
library(lattice)
data(singer)
histogram( ~ height | voice.part, data = singer,
xlab = "Height (inches)", type = "density",
panel = function(x, ...) {
panel.histogram(x, ...)
panel.mathdensity(dmath = dnorm,
args = list(mean=mean(x)...
} )
pp <- recordPlot(); png("lattice.histogram2.png"); rep...
}
#ref(lattice.histogram2.png,left)
*COLOR(red){densityplot} 関数
densityplot3 <- function() {
library(lattice)
data(singer)
densityplot( ~ height | voice.part, data = singer, lay...
xlab = "Height (inches)", bw = 5)
pp <- recordPlot(); png("lattice.densityplot1.png"); r...
}
#ref(lattice.histogram3.png,left)
*COLOR(red){levelplot} 関数
levelplot1 <- function() {
library(lattice)
x <- seq(pi/4, 5*pi, length = 100)
y <- seq(pi/4, 5*pi, length = 100)
r <- as.vector(sqrt(outer(x^2, y^2, "+")))
grid <- expand.grid(x=x, y=y)
grid$z <- cos(r^2) * exp(-r/(pi^3))
levelplot(z~x*y, grid, cuts = 50, xlab="", ylab="",
main="Weird Function", colorkey = FALSE)
}
#ref(lattice.levelplot1.png,left)
*COLOR(red){contourplot} 関数
contourplot1 <- function() { #S+ example
library(modreg)
library(lattice)
data(environmental)
attach(environmental)
ozo.m <- loess((ozone^(1/3)) ~ wind * temperature * ra...
parametric = c("radiation", "wind"), sp...
w.marginal <- seq(min(wind), max(wind), length = 50)
t.marginal <- seq(min(temperature), max(temperature), ...
r.marginal <- seq(min(radiation), max(radiation), leng...
wtr.marginal <- list(wind = w.marginal, temperature = ...
radiation = r.marginal)
grid <- expand.grid(wtr.marginal)
grid[, "fit"] <- c(predict(ozo.m, grid))
contourplot(fit ~ wind * temperature | radiation, data...
cuts = 10, region = TRUE,
xlab = "Wind Speed (mph)",
ylab = "Temperature (F)",
main = "Cube Root Ozone (cube root ppb)",
col.regions = trellis.par.get("regions")$c...
detach()
}
#ref(lattice.contourplot1.png,left)
*グラフの回転 r-help 記事より
> library(lattice)
> library(grid)
> myhist <- histogram(rnorm(50))
> # Make two square regions side by side
> push.viewport(viewport(layout=grid.layout(1, 2, respec...
> # Go to the left region
> push.viewport(viewport(layout.pos.col=1))
> # Draw the histogram in normal orientation
> print(myhist, newpage=FALSE)
> pop.viewport()
> # Go to the right region then rotate 90 degrees
> push.viewport(viewport(layout.pos.col=2), viewport(ang...
> # Draw the histogram (rotated 90 degrees)
> print(myhist, newpage=FALSE
> pop.viewport(3)
#ref(rotate.graph.png, left)
* P. Murrel の gridBase パッケージによるグラフィックス例 ...
gridBase.ex.1 <- function() {
#library(grid)
library(gridBase)
#library(lattice)
midpts <- barplot(1:10, axes=FALSE)
axis(2)
axis(1, at=midpts, labels=FALSE)
vps <- baseViewports()
par(new=TRUE)
push.viewport(vps$inner, vps$figure, vps$plot)
grid.text(c("0ne", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten"),
x = unit(midpts, "native"),
y = unit(-1, "lines"),
just = "right",
rot = 60)
pop.viewport(3)
}
#ref(gridBase1.png,left)
ページ名: