| 1 |
|
| 2 |
> options(prompt = "R> ", continue = "+ ") |
| 3 |
|
| 4 |
> library("colorspace") |
| 5 |
|
| 6 |
> library("vcd") |
| 7 |
Loading required package: grid |
| 8 |
|
| 9 |
> library("mvtnorm") |
| 10 |
|
| 11 |
> library("kernlab") |
| 12 |
|
| 13 |
> library("KernSmooth") |
| 14 |
KernSmooth 2.23 loaded |
| 15 |
Copyright M. P. Wand 1997-2009 |
| 16 |
|
| 17 |
> pal <- function(col, border = "light gray", ...) { |
| 18 |
+ n <- length(col) |
| 19 |
+ plot(0, 0, type = "n", xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, .... [TRUNCATED] |
| 20 |
|
| 21 |
> par(mfrow = c(2, 2), mar = c(0, 0, 3, 0)) |
| 22 |
|
| 23 |
> pal(rainbow_hcl(4, start = 30, end = 300), main = "dynamic") |
| 24 |
|
| 25 |
> pal(rainbow_hcl(4, start = 60, end = 240), main = "harmonic") |
| 26 |
|
| 27 |
> pal(rainbow_hcl(4, start = 270, end = 150), main = "cold") |
| 28 |
|
| 29 |
> pal(rainbow_hcl(4, start = 90, end = -30), main = "warm") |
| 30 |
|
| 31 |
> par(mfrow = c(5, 1), mar = c(0, 0, 0, 0)) |
| 32 |
|
| 33 |
> pal(sequential_hcl(12, c = 0, power = 2.2)) |
| 34 |
|
| 35 |
> pal(sequential_hcl(12, power = 2.2)) |
| 36 |
|
| 37 |
> pal(heat_hcl(12, c = c(80, 30), l = c(30, 90), power = c(1/5, |
| 38 |
+ 2))) |
| 39 |
|
| 40 |
> pal(terrain_hcl(12, c = c(65, 0), l = c(45, 90), power = c(1/2, |
| 41 |
+ 1.5))) |
| 42 |
|
| 43 |
> pal(rev(heat_hcl(12, h = c(0, -100), c = c(40, 80), |
| 44 |
+ l = c(75, 40), power = 1))) |
| 45 |
|
| 46 |
> par(mfrow = c(4, 1), mar = c(0, 0, 0, 0)) |
| 47 |
|
| 48 |
> pal(diverging_hcl(7)) |
| 49 |
|
| 50 |
> pal(diverging_hcl(7, c = 100, l = c(50, 90), power = 1)) |
| 51 |
|
| 52 |
> pal(diverging_hcl(7, h = c(130, 43), c = 100, l = c(70, |
| 53 |
+ 90))) |
| 54 |
|
| 55 |
> pal(diverging_hcl(7, h = c(180, 330), c = 59, l = c(75, |
| 56 |
+ 95))) |
| 57 |
|
| 58 |
> seats <- setNames(c(226, 61, 54, 51, 222), c("CDU/CSU", |
| 59 |
+ "FDP", "Linke", "Gruene", "SPD")) |
| 60 |
|
| 61 |
> seats |
| 62 |
CDU/CSU FDP Linke Gruene SPD |
| 63 |
226 61 54 51 222 |
| 64 |
|
| 65 |
> parties <- rainbow_hcl(6, c = 60, l = 75)[c(5, 2, |
| 66 |
+ 6, 3, 1)] |
| 67 |
|
| 68 |
> names(parties) <- names(seats) |
| 69 |
|
| 70 |
> par(mar = rep(0.8, 4)) |
| 71 |
|
| 72 |
> pie(seats, clockwise = TRUE, col = parties, radius = 1) |
| 73 |
|
| 74 |
> data("Bundestag2005", package = "vcd") |
| 75 |
|
| 76 |
> votes <- Bundestag2005[c(1, 3:5, 9, 11, 13:16, 2, |
| 77 |
+ 6:8, 10, 12), c("CDU/CSU", "FDP", "SPD", "Gruene", "Linke")] |
| 78 |
|
| 79 |
> mosaic(votes, gp = gpar(fill = parties[colnames(votes)]), |
| 80 |
+ spacing = spacing_highlighting, labeling = labeling_left, |
| 81 |
+ labeling_args = li .... [TRUNCATED] |
| 82 |
|
| 83 |
> library("KernSmooth") |
| 84 |
|
| 85 |
> data("geyser", package = "MASS") |
| 86 |
|
| 87 |
> dens <- bkde2D(geyser[, 2:1], bandwidth = c(0.2, 3), |
| 88 |
+ gridsize = c(201, 201)) |
| 89 |
|
| 90 |
> par(mfrow = c(1, 2)) |
| 91 |
|
| 92 |
> image(dens$x1, dens$x2, dens$fhat, xlab = "duration", |
| 93 |
+ ylab = "waiting time", col = rev(heat_hcl(33, c = 0, l = c(30, |
| 94 |
+ 90), power = .... [TRUNCATED] |
| 95 |
|
| 96 |
> box() |
| 97 |
|
| 98 |
> image(dens$x1, dens$x2, dens$fhat, xlab = "duration", |
| 99 |
+ ylab = "waiting time", col = rev(heat_hcl(33, c = c(80, 30), |
| 100 |
+ l = c(30, 90), .... [TRUNCATED] |
| 101 |
|
| 102 |
> box() |
| 103 |
|
| 104 |
> library("KernSmooth") |
| 105 |
|
| 106 |
> geyser2 <- cbind(geyser$duration[-299], geyser$waiting[-1]) |
| 107 |
|
| 108 |
> dens2 <- bkde2D(geyser2, bandwidth = c(0.2, 3), gridsize = c(201, |
| 109 |
+ 201)) |
| 110 |
|
| 111 |
> par(mfrow = c(1, 2)) |
| 112 |
|
| 113 |
> image(dens2$x1, dens2$x2, dens2$fhat, xlab = "duration", |
| 114 |
+ ylab = "waiting time", col = rev(heat_hcl(33, c = 0, l = c(30, |
| 115 |
+ 90), power .... [TRUNCATED] |
| 116 |
|
| 117 |
> box() |
| 118 |
|
| 119 |
> image(dens2$x1, dens2$x2, dens2$fhat, xlab = "duration", |
| 120 |
+ ylab = "waiting time", col = rev(heat_hcl(33, c = c(80, 30), |
| 121 |
+ l = c(30, 90 .... [TRUNCATED] |
| 122 |
|
| 123 |
> box() |
| 124 |
|
| 125 |
> art <- xtabs(~Treatment + Improved, data = Arthritis, |
| 126 |
+ subset = Sex == "Female") |
| 127 |
|
| 128 |
> set.seed(1071) |
| 129 |
|
| 130 |
> mosaic(art, gp = shading_max, gp_args = list(n = 5000)) |
| 131 |
|
| 132 |
> library("mvtnorm") |
| 133 |
|
| 134 |
> set.seed(123) |
| 135 |
|
| 136 |
> x1 <- rmvnorm(75, mean = c(1.5, 1.5), sigma = matrix(c(1, |
| 137 |
+ 0.8, 0.8, 1), ncol = 2)) |
| 138 |
|
| 139 |
> x2 <- rmvnorm(75, mean = c(-1, -1), sigma = matrix(c(1, |
| 140 |
+ -0.3, -0.3, 1), ncol = 2)) |
| 141 |
|
| 142 |
> X <- rbind(x1, x2) |
| 143 |
|
| 144 |
> ex1 <- data.frame(class = factor(c(rep("a", 75), rep("b", |
| 145 |
+ 75))), x1 = X[, 1], x2 = X[, 2]) |
| 146 |
|
| 147 |
> library("kernlab") |
| 148 |
|
| 149 |
> fm <- ksvm(class ~ ., data = ex1, C = 0.5) |
| 150 |
|
| 151 |
> suppressWarnings(plot(fm, data = ex1)) |
| 152 |
|
| 153 |
*** Run successfully completed *** |
| 154 |
> proc.time() |
| 155 |
user system elapsed |
| 156 |
2.264 0.108 2.363 |