如何在R ggplot2中更改geom_tile的调色板

时间:2014-08-08 04:02:55

标签: r ggplot2

我有以下数据用于绘制ggplot2的geom_tile:

ddf = structure(list(yy = c(60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L), xx = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 
7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 
27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 
29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 
31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 
32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 
33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 
34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 
35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 
36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 
37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 
38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 
39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 
41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 
42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 
43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 
44L, 44L, 44L, 44L, 44L, 44L, 44L, 44L, 44L, 44L, 44L, 44L, 44L, 
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 
46L, 46L, 46L, 46L, 46L, 46L, 46L, 46L, 46L, 46L, 46L, 46L, 46L, 
47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 
48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 
49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 
52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 
53L, 53L, 53L, 53L, 53L, 53L, 53L, 53L, 53L, 53L, 53L, 53L, 53L, 
54L, 54L, 54L, 54L, 54L, 54L, 54L, 54L, 54L, 54L, 54L, 54L, 54L, 
55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 
56L, 56L, 56L, 56L, 56L, 56L, 56L, 56L, 56L, 56L, 56L, 56L, 56L, 
57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 
58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 
59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 
60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 
61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 
62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 
63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 
64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 
65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 
66L, 66L, 66L, 66L, 66L, 66L, 66L, 66L, 66L, 66L, 66L, 66L, 66L, 
67L, 67L, 67L, 67L, 67L, 67L, 67L, 67L, 67L, 67L, 67L, 67L, 67L, 
68L, 68L, 68L, 68L, 68L, 68L, 68L, 68L, 68L, 68L, 68L, 68L, 68L, 
69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 69L, 
70L, 70L, 70L, 70L, 70L, 70L, 70L, 70L, 70L, 70L, 70L, 70L, 70L, 
71L, 71L, 71L, 71L, 71L, 71L, 71L, 71L, 71L, 71L, 71L, 71L, 71L, 
72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 
73L, 73L, 73L, 73L, 73L, 73L, 73L, 73L, 73L, 73L, 73L, 73L, 73L, 
74L, 74L, 74L, 74L, 74L, 74L, 74L, 74L, 74L, 74L, 74L, 74L, 74L, 
75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 
76L, 76L, 76L, 76L, 76L, 76L, 76L, 76L, 76L, 76L, 76L, 76L, 76L, 
77L, 77L, 77L, 77L, 77L, 77L, 77L, 77L, 77L, 77L, 77L, 77L, 77L, 
78L, 78L, 78L, 78L, 78L, 78L, 78L, 78L, 78L, 78L, 78L, 78L, 78L, 
79L, 79L, 79L, 79L, 79L, 79L, 79L, 79L, 79L, 79L, 79L, 79L, 79L, 
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 
81L, 81L, 81L, 81L, 81L, 81L, 81L, 81L, 81L, 81L, 81L, 81L, 81L
), .Label = c("50", "51", "52", "53", "54", "55", "56", "57", 
"58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", 
"69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", 
"80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", 
"91", "92", "93", "94", "95", "96", "97", "98", "99", "100", 
"101", "102", "103", "104", "105", "106", "107", "108", "109", 
"110", "111", "112", "113", "114", "115", "116", "117", "118", 
"119", "120", "121", "122", "123", "124", "125", "126", "127", 
"128", "129", "130"), class = "factor"), zz = c(22, 21, 20, 20, 
19, 18, 18, 17, 17, 16, 16, 15, 15, 22, 21, 21, 20, 19, 19, 18, 
18, 17, 17, 16, 16, 15, 22, 22, 21, 20, 20, 19, 19, 18, 17, 17, 
16, 16, 16, 23, 22, 21, 21, 20, 19, 19, 18, 18, 17, 17, 16, 16, 
23, 22, 22, 21, 20, 20, 19, 19, 18, 18, 17, 17, 16, 24, 23, 22, 
21, 21, 20, 20, 19, 18, 18, 17, 17, 16, 24, 23, 23, 22, 21, 21, 
20, 19, 19, 18, 18, 17, 17, 25, 24, 23, 22, 22, 21, 20, 20, 19, 
19, 18, 18, 17, 25, 24, 23, 23, 22, 21, 21, 20, 19, 19, 18, 18, 
17, 25, 25, 24, 23, 22, 22, 21, 20, 20, 19, 19, 18, 18, 26, 25, 
24, 23, 23, 22, 21, 21, 20, 20, 19, 18, 18, 26, 25, 25, 24, 23, 
22, 22, 21, 20, 20, 19, 19, 18, 27, 26, 25, 24, 23, 23, 22, 21, 
21, 20, 20, 19, 19, 27, 26, 25, 25, 24, 23, 22, 22, 21, 21, 20, 
19, 19, 28, 27, 26, 25, 24, 23, 23, 22, 21, 21, 20, 20, 19, 28, 
27, 26, 25, 25, 24, 23, 22, 22, 21, 21, 20, 19, 28, 27, 27, 26, 
25, 24, 23, 23, 22, 21, 21, 20, 20, 29, 28, 27, 26, 25, 25, 24, 
23, 22, 22, 21, 21, 20, 29, 28, 27, 27, 26, 25, 24, 23, 23, 22, 
22, 21, 20, 30, 29, 28, 27, 26, 25, 25, 24, 23, 22, 22, 21, 21, 
30, 29, 28, 27, 26, 26, 25, 24, 23, 23, 22, 22, 21, 31, 30, 29, 
28, 27, 26, 25, 25, 24, 23, 22, 22, 21, 31, 30, 29, 28, 27, 26, 
26, 25, 24, 23, 23, 22, 22, 31, 30, 29, 29, 28, 27, 26, 25, 24, 
24, 23, 22, 22, 32, 31, 30, 29, 28, 27, 26, 26, 25, 24, 23, 23, 
22, 32, 31, 30, 29, 28, 28, 27, 26, 25, 24, 24, 23, 22, 33, 32, 
31, 30, 29, 28, 27, 26, 25, 25, 24, 23, 23, 33, 32, 31, 30, 29, 
28, 27, 27, 26, 25, 24, 24, 23, 34, 32, 31, 30, 30, 29, 28, 27, 
26, 25, 25, 24, 23, 34, 33, 32, 31, 30, 29, 28, 27, 26, 26, 25, 
24, 24, 34, 33, 32, 31, 30, 29, 28, 28, 27, 26, 25, 25, 24, 35, 
34, 33, 32, 31, 30, 29, 28, 27, 26, 26, 25, 24, 35, 34, 33, 32, 
31, 30, 29, 28, 27, 27, 26, 25, 25, 36, 35, 33, 32, 31, 30, 30, 
29, 28, 27, 26, 26, 25, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 
27, 26, 25, 37, 35, 34, 33, 32, 31, 30, 29, 28, 28, 27, 26, 25, 
37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 26, 37, 36, 35, 
34, 33, 32, 31, 30, 29, 28, 28, 27, 26, 38, 37, 35, 34, 33, 32, 
31, 30, 29, 29, 28, 27, 26, 38, 37, 36, 35, 34, 33, 32, 31, 30, 
29, 28, 27, 27, 39, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 28, 
27, 39, 38, 37, 36, 34, 33, 32, 31, 31, 30, 29, 28, 27, 40, 38, 
37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 28, 40, 39, 38, 36, 35, 
34, 33, 32, 31, 30, 29, 29, 28, 40, 39, 38, 37, 36, 34, 33, 32, 
32, 31, 30, 29, 28, 41, 40, 38, 37, 36, 35, 34, 33, 32, 31, 30, 
29, 28, 41, 40, 39, 37, 36, 35, 34, 33, 32, 31, 30, 30, 29, 42, 
40, 39, 38, 37, 36, 35, 33, 33, 32, 31, 30, 29, 42, 41, 40, 38, 
37, 36, 35, 34, 33, 32, 31, 30, 29, 43, 41, 40, 39, 37, 36, 35, 
34, 33, 32, 31, 30, 30, 43, 42, 40, 39, 38, 37, 36, 35, 34, 33, 
32, 31, 30, 43, 42, 41, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 
44, 42, 41, 40, 39, 37, 36, 35, 34, 33, 32, 31, 30, 44, 43, 42, 
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 45, 43, 42, 41, 39, 38, 
37, 36, 35, 34, 33, 32, 31, 45, 44, 42, 41, 40, 39, 37, 36, 35, 
34, 33, 32, 31, 46, 44, 43, 41, 40, 39, 38, 37, 36, 35, 34, 33, 
32, 46, 45, 43, 42, 40, 39, 38, 37, 36, 35, 34, 33, 32, 47, 45, 
44, 42, 41, 40, 38, 37, 36, 35, 34, 33, 32, 47, 45, 44, 43, 41, 
40, 39, 38, 37, 35, 34, 34, 33, 47, 46, 44, 43, 42, 40, 39, 38, 
37, 36, 35, 34, 33, 48, 46, 45, 43, 42, 41, 39, 38, 37, 36, 35, 
34, 33, 48, 47, 45, 44, 42, 41, 40, 39, 38, 36, 35, 34, 33, 49, 
47, 46, 44, 43, 41, 40, 39, 38, 37, 36, 35, 34, 49, 47, 46, 45, 
43, 42, 41, 39, 38, 37, 36, 35, 34, 50, 48, 46, 45, 44, 42, 41, 
40, 39, 37, 36, 35, 34, 50, 48, 47, 45, 44, 43, 41, 40, 39, 38, 
37, 36, 35, 50, 49, 47, 46, 44, 43, 42, 40, 39, 38, 37, 36, 35, 
51, 49, 48, 46, 45, 43, 42, 41, 40, 38, 37, 36, 35, 51, 50, 48, 
46, 45, 44, 42, 41, 40, 39, 38, 37, 36, 52, 50, 48, 47, 45, 44, 
43, 41, 40, 39, 38, 37, 36, 52, 50, 49, 47, 46, 44, 43, 42, 41, 
39, 38, 37, 36, 53, 51, 49, 48, 46, 45, 43, 42, 41, 40, 39, 38, 
36, 53, 51, 50, 48, 47, 45, 44, 42, 41, 40, 39, 38, 37, 53, 52, 
50, 48, 47, 45, 44, 43, 42, 40, 39, 38, 37, 54, 52, 50, 49, 47, 
46, 44, 43, 42, 41, 40, 38, 37, 54, 52, 51, 49, 48, 46, 45, 44, 
42, 41, 40, 39, 38, 55, 53, 51, 50, 48, 47, 45, 44, 43, 41, 40, 
39, 38, 55, 53, 52, 50, 48, 47, 46, 44, 43, 42, 40, 39, 38, 56, 
54, 52, 50, 49, 47, 46, 45, 43, 42, 41, 40, 39, 56, 54, 52, 51, 
49, 48, 46, 45, 44, 42, 41, 40, 39)), row.names = c(NA, -1053L
), .Names = c("yy", "xx", "zz"), class = "data.frame")

library(ggplot2)
ggplot(ddf) + geom_tile(aes(x=xx, y=yy, fill=zz))

它使用默认蓝色阴影绘制绘图。但是如何为这个geom_tile图使用以下调色板:

colorRampPalette(c("blue", "green", "yellow", "red"))

感谢您的帮助。

1 个答案:

答案 0 :(得分:5)

ggplot2中有一个很好的指南:http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/

在您的情况下,由于ddf$zz只有42个唯一级别,您可以尝试这样做:

> length(unique(ddf$zz))
[1] 42
> colors <- colorRampPalette(c("blue", "green", "yellow", "red"))(42)
> ggplot(ddf) + geom_tile(aes(x=xx, y=yy, fill=factor(zz))) + 
     scale_fill_manual(values=colors)

rnso指出,上面的代码会生成一个很长的图例,不能适应画布。解决这个问题:

> ddf$zz <- factor(ddf$zz)
> N <- nlevels(ddf$zz)
> ggplot(ddf) + geom_tile(aes(x=xx, y=yy, fill=zz)) + 
    scale_fill_manual(values=colors, breaks=levels(ddf$zz)[seq(1, N, by=5)])

产生:

enter image description here