ggplot2中不同的颜色索引

问题描述 投票:0回答:1

我正在绘制一些光照水平数据,并希望覆盖黄昏(日出和日落)。这些需要采用两种色标,在咨询了 chatGPT 和 google 后,我不知道该怎么做!如果我能得到任何帮助,我将不胜感激。

ggplot() +
  geom_point(data, mapping = aes(x = EST_Date, y = shifted_minutes, color = light_log), shape = 15) +
  geom_point(data_twilight, mapping =  aes(x = EST_Date, y = shifted_minutes, fill = twilight)) +
  scale_y_continuous(
    breaks = y_breaks,
    labels = y_labels,
    limits = c(0, 1440)
  ) +
  labs(
    x = "Value",
    y = "Time"
  ) +
  scale_fill_manual(values = c("sunrise" ="orange", "sunset"="blue")) +
  scale_color_gradient(low = "black", high = "white")   +
  theme_minimal() +
geom_hline(yintercept = y_breaks, color = "red", linetype = "solid")

这基本上是完美的,除了我的日出和日落是黑色的。我也尝试过scale_color_manual和scale_color_discrete,但没有成功。 enter image description here

我的数据集太大,无法使用 dput 插入,因此我只包含前 50 行。这将导致你的图表看起来与我的不同。

> dput(head(data, n=50))
structure(list(datetime = structure(c(1677647073, 1677647373, 
1677647673, 1677647973, 1677648273, 1677648573, 1677648873, 1677649173, 
1677649473, 1677649773, 1677650073, 1677650373, 1677650673, 1677650973, 
1677651273, 1677651573, 1677651873, 1677652173, 1677652473, 1677652773, 
1677653073, 1677653373, 1677653673, 1677653973, 1677654273, 1677654573, 
1677654873, 1677655173, 1677655473, 1677655773, 1677656073, 1677656373, 
1677656673, 1677656973, 1677657273, 1677657573, 1677657873, 1677658173, 
1677658473, 1677658773, 1677659073, 1677659373, 1677659673, 1677659973, 
1677660273, 1677660573, 1677660873, 1677661173, 1677661473, 1677661773
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), light = c(1.136, 
1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 
1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 
1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 
1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 
1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 1.136, 
1.136, 1.136, 1.136, 1.136), twilight = c("night", "night", "night", 
"night", "night", "night", "night", "night", "night", "night", 
"night", "night", "night", "night", "night", "night", "night", 
"night", "night", "night", "night", "night", "night", "night", 
"night", "night", "night", "night", "night", "night", "night", 
"night", "night", "night", "night", "night", "night", "night", 
"night", "night", "night", "night", "night", "night", "night", 
"night", "night", "night", "night", "night"), EST_datetime = structure(c(1677647073, 
1677647373, 1677647673, 1677647973, 1677648273, 1677648573, 1677648873, 
1677649173, 1677649473, 1677649773, 1677650073, 1677650373, 1677650673, 
1677650973, 1677651273, 1677651573, 1677651873, 1677652173, 1677652473, 
1677652773, 1677653073, 1677653373, 1677653673, 1677653973, 1677654273, 
1677654573, 1677654873, 1677655173, 1677655473, 1677655773, 1677656073, 
1677656373, 1677656673, 1677656973, 1677657273, 1677657573, 1677657873, 
1677658173, 1677658473, 1677658773, 1677659073, 1677659373, 1677659673, 
1677659973, 1677660273, 1677660573, 1677660873, 1677661173, 1677661473, 
1677661773), class = c("POSIXct", "POSIXt"), tzone = "America/New_York"), 
    EST_time = structure(c(273, 573, 873, 1173, 1473, 1773, 2073, 
    2373, 2673, 2973, 3273, 3573, 3873, 4173, 4473, 4773, 5073, 
    5373, 5673, 5973, 6273, 6573, 6873, 7173, 7473, 7773, 8073, 
    8373, 8673, 8973, 9273, 9573, 9873, 10173, 10473, 10773, 
    11073, 11373, 11673, 11973, 12273, 12573, 12873, 13173, 13473, 
    13773, 14073, 14373, 14673, 14973), class = c("POSIXct", 
    "POSIXt"), tzone = "UTC"), EST_Date = structure(c(19417, 
    19417, 19417, 19417, 19417, 19417, 19417, 19417, 19417, 19417, 
    19417, 19417, 19417, 19417, 19417, 19417, 19417, 19417, 19417, 
    19417, 19417, 19417, 19417, 19417, 19417, 19417, 19417, 19417, 
    19417, 19417, 19417, 19417, 19417, 19417, 19417, 19417, 19417, 
    19417, 19417, 19417, 19417, 19417, 19417, 19417, 19417, 19417, 
    19417, 19417, 19417, 19417), class = "Date"), band_number = c("2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150"), 
    light_log = c(0.12751332029896, 0.12751332029896, 0.12751332029896, 
    0.12751332029896, 0.12751332029896, 0.12751332029896, 0.12751332029896, 
    0.12751332029896, 0.12751332029896, 0.12751332029896, 0.12751332029896, 
    0.12751332029896, 0.12751332029896, 0.12751332029896, 0.12751332029896, 
    0.12751332029896, 0.12751332029896, 0.12751332029896, 0.12751332029896, 
    0.12751332029896, 0.12751332029896, 0.12751332029896, 0.12751332029896, 
    0.12751332029896, 0.12751332029896, 0.12751332029896, 0.12751332029896, 
    0.12751332029896, 0.12751332029896, 0.12751332029896, 0.12751332029896, 
    0.12751332029896, 0.12751332029896, 0.12751332029896, 0.12751332029896, 
    0.12751332029896, 0.12751332029896, 0.12751332029896, 0.12751332029896, 
    0.12751332029896, 0.12751332029896, 0.12751332029896, 0.12751332029896, 
    0.12751332029896, 0.12751332029896, 0.12751332029896, 0.12751332029896, 
    0.12751332029896, 0.12751332029896, 0.12751332029896), Month = structure(c(3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L), levels = c("Jan", "Feb", "Mar", "Apr", "May", 
    "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"), class = c("ordered", 
    "factor")), minutes = c(4, 9, 14, 19, 24, 29, 34, 39, 44, 
    49, 54, 59, 64, 69, 74, 79, 84, 89, 94, 99, 104, 109, 114, 
    119, 124, 129, 134, 139, 144, 149, 154, 159, 164, 169, 174, 
    179, 184, 189, 194, 199, 204, 209, 214, 219, 224, 229, 234, 
    239, 244, 249), shifted_minutes = c(544, 549, 554, 559, 564, 
    569, 574, 579, 584, 589, 594, 599, 604, 609, 614, 619, 624, 
    629, 634, 639, 644, 649, 654, 659, 664, 669, 674, 679, 684, 
    689, 694, 699, 704, 709, 714, 719, 724, 729, 734, 739, 744, 
    749, 754, 759, 764, 769, 774, 779, 784, 789)), row.names = c(NA, 
50L), class = "data.frame")
> dput(head(data_twilight, n=50)
+ )
structure(list(datetime = structure(c(1677670140, 1677712740, 
1677756300, 1677800040, 1677842040, 1677886320, 1677928740, 1677973440, 
1678014900, 1678059540, 1678101000, 1678146180, 1678187100, 1678232640, 
1678273560, 1678319340, 1678359840, 1678406040, 1678446000, 1678491540, 
1678532400, 1678577940, 1678619100, 1678664880, 1678705260, 1678751580, 
1678792200, 1678837980, 1678877700, 1678924980, 1678963800, 1679010840, 
1679050800, 1679096640, 1679137200, 1679183580, 1679223360, 1679270580, 
1679309460, 1679356740, 1679396400, 1679443380, 1679481300, 1679529540, 
1679568600, 1679616840, 1679654400, 1679702640, 1679740800, 1679789040
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), light = c(1.5, 
1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 
1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 
1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 
1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5), twilight = structure(c(1L, 
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
2L), levels = c("sunrise", "sunset"), class = "factor"), EST_datetime = structure(c(1677670140, 
1677712740, 1677756300, 1677800040, 1677842040, 1677886320, 1677928740, 
1677973440, 1678014900, 1678059540, 1678101000, 1678146180, 1678187100, 
1678232640, 1678273560, 1678319340, 1678359840, 1678406040, 1678446000, 
1678491540, 1678532400, 1678577940, 1678619100, 1678664880, 1678705260, 
1678751580, 1678792200, 1678837980, 1678877700, 1678924980, 1678963800, 
1679010840, 1679050800, 1679096640, 1679137200, 1679183580, 1679223360, 
1679270580, 1679309460, 1679356740, 1679396400, 1679443380, 1679481300, 
1679529540, 1679568600, 1679616840, 1679654400, 1679702640, 1679740800, 
1679789040), class = c("POSIXct", "POSIXt"), tzone = "America/New_York"), 
    EST_time = structure(c(23340, 65940, 23100, 66840, 22440, 
    66720, 22740, 67440, 22500, 67140, 22200, 67380, 21900, 67440, 
    21960, 67740, 21840, 68040, 21600, 67140, 21600, 67140, 25500, 
    71280, 25260, 71580, 25800, 71580, 24900, 72180, 24600, 71640, 
    25200, 71040, 25200, 71580, 24960, 72180, 24660, 71940, 25200, 
    72180, 23700, 71940, 24600, 72840, 24000, 72240, 24000, 72240
    ), class = c("POSIXct", "POSIXt"), tzone = "UTC"), EST_Date = structure(c(19417, 
    19417, 19418, 19418, 19419, 19419, 19420, 19420, 19421, 19421, 
    19422, 19422, 19423, 19423, 19424, 19424, 19425, 19425, 19426, 
    19426, 19427, 19427, 19428, 19428, 19429, 19429, 19430, 19430, 
    19431, 19431, 19432, 19432, 19433, 19433, 19434, 19434, 19435, 
    19435, 19436, 19436, 19437, 19437, 19438, 19438, 19439, 19439, 
    19440, 19440, 19441, 19441), class = "Date"), band_number = c("2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150", "2227_58150", 
    "2227_58150", "2227_58150", "2227_58150", "2227_58150"), 
    light_log = c(0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164, 0.405465108108164, 
    0.405465108108164, 0.405465108108164), Month = structure(c(3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L), levels = c("Jan", "Feb", "Mar", "Apr", "May", 
    "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"), class = c("ordered", 
    "factor")), minutes = c(389, 1099, 385, 1114, 374, 1112, 
    379, 1124, 375, 1119, 370, 1123, 365, 1124, 366, 1129, 364, 
    1134, 360, 1119, 360, 1119, 425, 1188, 421, 1193, 430, 1193, 
    415, 1203, 410, 1194, 420, 1184, 420, 1193, 416, 1203, 411, 
    1199, 420, 1203, 395, 1199, 410, 1214, 400, 1204, 400, 1204
    ), shifted_minutes = c(929, 199, 925, 214, 914, 212, 919, 
    224, 915, 219, 910, 223, 905, 224, 906, 229, 904, 234, 900, 
    219, 900, 219, 965, 288, 961, 293, 970, 293, 955, 303, 950, 
    294, 960, 284, 960, 293, 956, 303, 951, 299, 960, 303, 935, 
    299, 950, 314, 940, 304, 940, 304)), row.names = c(NA, 50L
), class = "data.frame")

如果您想要更多数据,我深表歉意,但我现在无法上传这些数据的文件。

谢谢!

r ggplot2
1个回答
0
投票

您忘记添加了吗

, shape = 21

到绘制 data_twilight 的 geom_point() ?尝试一下

geom_point(data_twilight, mapping =  aes(x = EST_Date, y = shifted_minutes, fill = twilight), shape = 21) +
 
© www.soinside.com 2019 - 2024. All rights reserved.