Error in categorical color mapping ggplot2

Hello!

I am trying to create a time series graph of temperature as a function of time for several different sites. I want to color code my observations according to site, but I'm getting this error:

Error in layer(data = data, mapping = mapping, stat = stat, geom = GeomPoint, : object 'SITE_ID' not found

Not sure what I'm doing wrong. It must be something with the data but I'm not sure what. Here is my code:

temp <- dmean %>% 
  ggplot() +
  geom_line(aes(x=DATE,
                y=TEMP_C),
            col=SITE_ID)

And here is some of my data:

dmean <- structure(list(SITE_ID = c("BI22_01", "BI22_01", "BI22_01", "BI22_01", 
"BI22_01", "BI22_01", "BI22_01", "BI22_01", "BI22_01", "BI22_01", 
"BI22_01", "BI22_02", "BI22_02", "BI22_02", "BI22_02", "BI22_02", 
"BI22_02", "BI22_02", "BI22_02", "BI22_02", "BI22_02", "BI22_02", 
"BI22_03", "BI22_03", "BI22_03"), DATE = structure(c(19138, 19145, 
19151, 19156, 19164, 19171, 19178, 19185, 19191, 19201, 19208, 
19138, 19145, 19151, 19156, 19164, 19171, 19178, 19185, 19191, 
19201, 19208, 19138, 19145, 19151), class = "Date"), TEMP_C = c(15.2816666666667, 
14.74375, 22.25375, 16.08625, 19.3875, 19.55625, 19.805, 21.8875, 
24.94, 20.77, 21.08375, 13.665, 16.7375, 19.46375, 17.60375, 
22.205, 20.10625, 18.535, 21.4325, 28.5875, 21.2025, 26.1025, 
15.545, 17.1525, 20.8716666666667), COND_US = c(0.1075, 0.11925, 
0.2765, 0.135, 0.121375, 0.139, 0.137125, 0.13725, 0.143, 0.13825, 
0.14025, 0.13025, 0.13525, 0.1345, 0.13425, 0.136, 0.13975, 0.145, 
0.142125, 0.149625, 0.14375, 0.135, 0.1395, 0.141, 0.134666666666667
), DO_MG_L = c(9.34833333333333, 8.8825, 9.17625, 8.31875, 7.94625, 
8.55, 9.0175, 8.36125, 7.15375, 8.005, 9.6125, 9.07, 8.4375, 
9.07875, 7.63375, 7.9075, 7.43125, 8.15375, 7.275, 10.07875, 
8.28125, 8.9325, 9.275, 8.245, 8.45833333333333), PH = c(7.76, 
7.48125, 7.33, 7.3825, 7.51875, 7.5855, 7.685, 7.6175, 7.685, 
7.49, 7.61625, 7.41, 7.36875, 7.18125, 7.28875, 7.5225, 7.5825, 
6.90125, 7.77125, 8.295, 7.8025, 8.07, 7.885, 7.605, 7.16833333333333
), TURB_NU = c(7.4, 9.5625, 14.075, 3.15, 3.0625, NA, NA, 1.6875, 
NA, NA, 3.2375, 15.175, 114.925, 3.5625, 1.45, 4.175, 3.1875, 
NA, 9.8375, 0.6875, NA, 3.95, 3.4, 10.7, 7.75)), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -25L), groups = structure(list(
    SITE_ID = c("BI22_01", "BI22_02", "BI22_03"), .rows = structure(list(
        1:11, 12:22, 23:25), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -3L), .drop = TRUE))

Any help would be greatly appreciated. Thanks so much!

The assignment of the line color to the SITE_ID column needs to be done inside of the aes().

dmean %>% 
  ggplot() +
  geom_line(aes(x=DATE,
                y=TEMP_C,color=SITE_ID))
1 Like

Omg... Been away from R too long. Thanks so much for your help!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.