質問編集履歴
2
できました!
test
CHANGED
File without changes
|
test
CHANGED
@@ -219,231 +219,3 @@
|
|
219
219
|
|
220
220
|
|
221
221
|
こういった事は、できるのでしょうか、どのようにするのでしょう・・・。
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
教えて貰ったコードだと、このようになってしまいました・・・。
|
226
|
-
|
227
|
-
![イメージ説明](aded0fd4a1afbf9cdcfc17e33af52dcc.png)
|
228
|
-
|
229
|
-
どこが違うのでしょうか。
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
```R
|
234
|
-
|
235
|
-
pie315 <- function (x, labels = names(x), edges = 200, radius = 0.8, clockwise = FALSE,
|
236
|
-
|
237
|
-
init.angle = if (clockwise) 90 else 0, density = NULL, angle = 45,
|
238
|
-
|
239
|
-
col = NULL, border = NULL, lty = NULL, main = NULL, ...)
|
240
|
-
|
241
|
-
{
|
242
|
-
|
243
|
-
if (!is.numeric(x) || any(is.na(x) | x < 0))
|
244
|
-
|
245
|
-
stop("'x' values must be positive.")
|
246
|
-
|
247
|
-
if (is.null(labels))
|
248
|
-
|
249
|
-
labels <- as.character(seq_along(x))
|
250
|
-
|
251
|
-
else labels <- as.graphicsAnnot(labels)
|
252
|
-
|
253
|
-
x <- c(0, cumsum(x)/sum(x))
|
254
|
-
|
255
|
-
dx <- diff(x)
|
256
|
-
|
257
|
-
nx <- length(dx)
|
258
|
-
|
259
|
-
plot.new()
|
260
|
-
|
261
|
-
pin <- par("pin")
|
262
|
-
|
263
|
-
xlim <- ylim <- c(-1, 1)
|
264
|
-
|
265
|
-
if (pin[1L] > pin[2L])
|
266
|
-
|
267
|
-
xlim <- (pin[1L]/pin[2L]) * xlim
|
268
|
-
|
269
|
-
else ylim <- (pin[2L]/pin[1L]) * ylim
|
270
|
-
|
271
|
-
dev.hold()
|
272
|
-
|
273
|
-
on.exit(dev.flush())
|
274
|
-
|
275
|
-
plot.window(xlim, ylim, "", asp = 1)
|
276
|
-
|
277
|
-
if (is.null(col))
|
278
|
-
|
279
|
-
col <- if (is.null(density))
|
280
|
-
|
281
|
-
c("white", "lightblue", "mistyrose", "lightcyan",
|
282
|
-
|
283
|
-
"lavender", "cornsilk")
|
284
|
-
|
285
|
-
else par("fg")
|
286
|
-
|
287
|
-
if (!is.null(col))
|
288
|
-
|
289
|
-
col <- rep_len(col, nx)
|
290
|
-
|
291
|
-
if (!is.null(border))
|
292
|
-
|
293
|
-
border <- rep_len(border, nx)
|
294
|
-
|
295
|
-
if (!is.null(lty))
|
296
|
-
|
297
|
-
lty <- rep_len(lty, nx)
|
298
|
-
|
299
|
-
angle <- rep(angle, nx)
|
300
|
-
|
301
|
-
if (!is.null(density))
|
302
|
-
|
303
|
-
density <- rep_len(density, nx)
|
304
|
-
|
305
|
-
twopi <- if (clockwise)
|
306
|
-
|
307
|
-
-2 * pi
|
308
|
-
|
309
|
-
else 2 * pi
|
310
|
-
|
311
|
-
t2xy <- function(t) {
|
312
|
-
|
313
|
-
t2p <- twopi * t + init.angle * pi/180
|
314
|
-
|
315
|
-
list(x = radius * cos(t2p), y = radius * sin(t2p))
|
316
|
-
|
317
|
-
}
|
318
|
-
|
319
|
-
for (i in 1L:nx) {
|
320
|
-
|
321
|
-
n <- max(2, floor(edges * dx[i]))
|
322
|
-
|
323
|
-
P <- t2xy(seq.int(x[i], x[i + 1], length.out = n))
|
324
|
-
|
325
|
-
polygon(c(P$x, 0), c(P$y, 0), density = density[i], angle = angle[i],
|
326
|
-
|
327
|
-
border = border[i], col = col[i], lty = lty[i])
|
328
|
-
|
329
|
-
P <- t2xy(mean(x[i + 0:1]))
|
330
|
-
|
331
|
-
lab <- as.character(labels[i])
|
332
|
-
|
333
|
-
if (!is.na(lab) && nzchar(lab)) {
|
334
|
-
|
335
|
-
text(0.92 * P$x, 0.85 * P$y, labels[i], xpd = TRUE,
|
336
|
-
|
337
|
-
adj = ifelse(P$x > 0, 1, 0), ...)
|
338
|
-
|
339
|
-
}
|
340
|
-
|
341
|
-
}
|
342
|
-
|
343
|
-
title(main = main, ...)
|
344
|
-
|
345
|
-
invisible(NULL)
|
346
|
-
|
347
|
-
}
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
png("graph.png", width = 800, height = 700) # 描画デバイスを開く
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
x <- c(20, 15, 10, 5)
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
# 外側の円
|
360
|
-
|
361
|
-
pie315(x,
|
362
|
-
|
363
|
-
radius=0.6, # 半径
|
364
|
-
|
365
|
-
clockwise=T,
|
366
|
-
|
367
|
-
labels=c("A","B","C","D"),
|
368
|
-
|
369
|
-
cex=2,
|
370
|
-
|
371
|
-
col=c("red","green","blue","gray"),
|
372
|
-
|
373
|
-
border=F)
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
# 重ね描き
|
378
|
-
|
379
|
-
par(new=TRUE)
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
pie315(x, # ダミー
|
384
|
-
|
385
|
-
radius=0.62, # 半径(内円の半径は 0.6)
|
386
|
-
|
387
|
-
col="white", # 領域の色
|
388
|
-
|
389
|
-
border="white", # 枠線の色
|
390
|
-
|
391
|
-
labels="") # ラベル非表示
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
# 重ね描き
|
396
|
-
|
397
|
-
par(new=TRUE)
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
pie315(x,
|
402
|
-
|
403
|
-
radius=0.6, # 半径
|
404
|
-
|
405
|
-
clockwise=T,
|
406
|
-
|
407
|
-
labels=c("A","B","C","D"),
|
408
|
-
|
409
|
-
cex=2,
|
410
|
-
|
411
|
-
col=c("red","green","blue","gray"))
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
# 重ね描き
|
416
|
-
|
417
|
-
par(new=TRUE)
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
# 中央の白円
|
422
|
-
|
423
|
-
pie315(1, # ダミー
|
424
|
-
|
425
|
-
radius=0.4, # 半径
|
426
|
-
|
427
|
-
col="white", # 領域の色
|
428
|
-
|
429
|
-
border="white", # 枠線の色
|
430
|
-
|
431
|
-
labels="") # ラベル非表示
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
# テキストの挿入
|
436
|
-
|
437
|
-
text(0, 0, # 挿入位置
|
438
|
-
|
439
|
-
labels="pie12",
|
440
|
-
|
441
|
-
cex=3,
|
442
|
-
|
443
|
-
col="red")
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
dev.off()
|
448
|
-
|
449
|
-
```
|
1
進捗を書きました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -219,3 +219,231 @@
|
|
219
219
|
|
220
220
|
|
221
221
|
こういった事は、できるのでしょうか、どのようにするのでしょう・・・。
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
教えて貰ったコードだと、このようになってしまいました・・・。
|
226
|
+
|
227
|
+
![イメージ説明](aded0fd4a1afbf9cdcfc17e33af52dcc.png)
|
228
|
+
|
229
|
+
どこが違うのでしょうか。
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
```R
|
234
|
+
|
235
|
+
pie315 <- function (x, labels = names(x), edges = 200, radius = 0.8, clockwise = FALSE,
|
236
|
+
|
237
|
+
init.angle = if (clockwise) 90 else 0, density = NULL, angle = 45,
|
238
|
+
|
239
|
+
col = NULL, border = NULL, lty = NULL, main = NULL, ...)
|
240
|
+
|
241
|
+
{
|
242
|
+
|
243
|
+
if (!is.numeric(x) || any(is.na(x) | x < 0))
|
244
|
+
|
245
|
+
stop("'x' values must be positive.")
|
246
|
+
|
247
|
+
if (is.null(labels))
|
248
|
+
|
249
|
+
labels <- as.character(seq_along(x))
|
250
|
+
|
251
|
+
else labels <- as.graphicsAnnot(labels)
|
252
|
+
|
253
|
+
x <- c(0, cumsum(x)/sum(x))
|
254
|
+
|
255
|
+
dx <- diff(x)
|
256
|
+
|
257
|
+
nx <- length(dx)
|
258
|
+
|
259
|
+
plot.new()
|
260
|
+
|
261
|
+
pin <- par("pin")
|
262
|
+
|
263
|
+
xlim <- ylim <- c(-1, 1)
|
264
|
+
|
265
|
+
if (pin[1L] > pin[2L])
|
266
|
+
|
267
|
+
xlim <- (pin[1L]/pin[2L]) * xlim
|
268
|
+
|
269
|
+
else ylim <- (pin[2L]/pin[1L]) * ylim
|
270
|
+
|
271
|
+
dev.hold()
|
272
|
+
|
273
|
+
on.exit(dev.flush())
|
274
|
+
|
275
|
+
plot.window(xlim, ylim, "", asp = 1)
|
276
|
+
|
277
|
+
if (is.null(col))
|
278
|
+
|
279
|
+
col <- if (is.null(density))
|
280
|
+
|
281
|
+
c("white", "lightblue", "mistyrose", "lightcyan",
|
282
|
+
|
283
|
+
"lavender", "cornsilk")
|
284
|
+
|
285
|
+
else par("fg")
|
286
|
+
|
287
|
+
if (!is.null(col))
|
288
|
+
|
289
|
+
col <- rep_len(col, nx)
|
290
|
+
|
291
|
+
if (!is.null(border))
|
292
|
+
|
293
|
+
border <- rep_len(border, nx)
|
294
|
+
|
295
|
+
if (!is.null(lty))
|
296
|
+
|
297
|
+
lty <- rep_len(lty, nx)
|
298
|
+
|
299
|
+
angle <- rep(angle, nx)
|
300
|
+
|
301
|
+
if (!is.null(density))
|
302
|
+
|
303
|
+
density <- rep_len(density, nx)
|
304
|
+
|
305
|
+
twopi <- if (clockwise)
|
306
|
+
|
307
|
+
-2 * pi
|
308
|
+
|
309
|
+
else 2 * pi
|
310
|
+
|
311
|
+
t2xy <- function(t) {
|
312
|
+
|
313
|
+
t2p <- twopi * t + init.angle * pi/180
|
314
|
+
|
315
|
+
list(x = radius * cos(t2p), y = radius * sin(t2p))
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
for (i in 1L:nx) {
|
320
|
+
|
321
|
+
n <- max(2, floor(edges * dx[i]))
|
322
|
+
|
323
|
+
P <- t2xy(seq.int(x[i], x[i + 1], length.out = n))
|
324
|
+
|
325
|
+
polygon(c(P$x, 0), c(P$y, 0), density = density[i], angle = angle[i],
|
326
|
+
|
327
|
+
border = border[i], col = col[i], lty = lty[i])
|
328
|
+
|
329
|
+
P <- t2xy(mean(x[i + 0:1]))
|
330
|
+
|
331
|
+
lab <- as.character(labels[i])
|
332
|
+
|
333
|
+
if (!is.na(lab) && nzchar(lab)) {
|
334
|
+
|
335
|
+
text(0.92 * P$x, 0.85 * P$y, labels[i], xpd = TRUE,
|
336
|
+
|
337
|
+
adj = ifelse(P$x > 0, 1, 0), ...)
|
338
|
+
|
339
|
+
}
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
title(main = main, ...)
|
344
|
+
|
345
|
+
invisible(NULL)
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
png("graph.png", width = 800, height = 700) # 描画デバイスを開く
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
x <- c(20, 15, 10, 5)
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
# 外側の円
|
360
|
+
|
361
|
+
pie315(x,
|
362
|
+
|
363
|
+
radius=0.6, # 半径
|
364
|
+
|
365
|
+
clockwise=T,
|
366
|
+
|
367
|
+
labels=c("A","B","C","D"),
|
368
|
+
|
369
|
+
cex=2,
|
370
|
+
|
371
|
+
col=c("red","green","blue","gray"),
|
372
|
+
|
373
|
+
border=F)
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
# 重ね描き
|
378
|
+
|
379
|
+
par(new=TRUE)
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
pie315(x, # ダミー
|
384
|
+
|
385
|
+
radius=0.62, # 半径(内円の半径は 0.6)
|
386
|
+
|
387
|
+
col="white", # 領域の色
|
388
|
+
|
389
|
+
border="white", # 枠線の色
|
390
|
+
|
391
|
+
labels="") # ラベル非表示
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
# 重ね描き
|
396
|
+
|
397
|
+
par(new=TRUE)
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
pie315(x,
|
402
|
+
|
403
|
+
radius=0.6, # 半径
|
404
|
+
|
405
|
+
clockwise=T,
|
406
|
+
|
407
|
+
labels=c("A","B","C","D"),
|
408
|
+
|
409
|
+
cex=2,
|
410
|
+
|
411
|
+
col=c("red","green","blue","gray"))
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
# 重ね描き
|
416
|
+
|
417
|
+
par(new=TRUE)
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
# 中央の白円
|
422
|
+
|
423
|
+
pie315(1, # ダミー
|
424
|
+
|
425
|
+
radius=0.4, # 半径
|
426
|
+
|
427
|
+
col="white", # 領域の色
|
428
|
+
|
429
|
+
border="white", # 枠線の色
|
430
|
+
|
431
|
+
labels="") # ラベル非表示
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
# テキストの挿入
|
436
|
+
|
437
|
+
text(0, 0, # 挿入位置
|
438
|
+
|
439
|
+
labels="pie12",
|
440
|
+
|
441
|
+
cex=3,
|
442
|
+
|
443
|
+
col="red")
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
dev.off()
|
448
|
+
|
449
|
+
```
|