This is an example of my data:
HUC8 YEAR RO_MM
bcc1_45Fall_1020004 1961 112.0
bcc1_45Fall_1020004 1962 243.7
bcc1_45Fall_1020004 1963 233.3
bcc1_45Fall_1020004 1964 190.3
bcc1_M_45Fall_1020004 1961 100.9
bcc1_M_45Fall_1020004 1962 132.3
bcc1_M_45Fall_1020004 1963 255.1
bcc1_M_45Fall_1020004 1964 281.9
bnuesm_45Fall_1020004 1961 89.0
bnuesm_45Fall_1020004 1962 89.5
bnuesm_45Fall_1020004 1963 126.8
bnuesm_45Fall_1020004 1964 194.3
canesm2_45Fall_1020004 1961 186.6
canesm2_45Fall_1020004 1962 197.4
canesm2_45Fall_1020004 1963 229.1
canesm2_45Fall_1020004 1964 141.8
Each of the similar prefixes represents (a segment of) a single csv. I have called them into a list and used rbind to link them. My goal is to have each csv represent a line of data, which would look like this:
Name
1961 1962 1963 1964 ...
bcc1_45Fall_1020004 112.0 243.7 233.3 190.3
bcc1_M_45Fall_1020004 100.9 132.3 255.1 281.9
bnuesm_45Fall_1020004 89.0 89.5 126.8 194.3
canesm2_45Fall_1020004 186.6 197.4 229.1 141.8
I would then like to plot these lines in a line graph using ggplot2where each Name becomes a line of "RO_MM" data over 140 years. Remember, this is only a tiny sample. There are actually hundreds of files. I know that hundreds is too many for a graph and plan to do them in smaller groups, but I DO NOT need to grid them together. I have so far used this code which has provided the initial datalist above:
library(rio)
library(tidyverse)
library(data.table)
file_names <- list.files("~/Desktop/Rproj/splitByHUCs45/a01020004/splFall")
data_list <- lapply(file_names, read.csv , header=TRUE, sep=",")
finalTable <- do.call(rbind, data_list)
I have found this code (below). It is not what I need because I don't need the mean of anything, but I saw that it used more than one csv for input, so I'm trying to make sense of it, but don't know how to make it work for me.
#some pseudo data for testing
my_other_data <- myData
my_other_data$Data <- my_other_data$Data * 0.5
pplot <- ggplot(data=myData, aes(x=Group, y=Data)) +
stat_summary(fun = mean, geom = "line", color='red') +
stat_summary(data=my_other_data, aes(x=Group, y=Data),
fun = mean, geom = "line", color='green') +
xlab("Group") +
ylab("Data")
pplot
That said, the page on creating a reprex said that I should provide you with this:
head(finalTable, 3) %>%
+ deparse()
[1] "structure(list(HUC8 = structure(c(1L, 1L, 1L), .Label = c(\"bcc1_45Fall_1020004\", "
[2] "\"bcc1_M_45Fall_1020004\", \"bnuesm_45Fall_1020004\", \"canesm2_45Fall_1020004\", "
[3] "\"ccsm4_45Fall_1020004\", \"cnrmcm5_45Fall_1020004\", \"csiromk360_45Fall_1020004\", "
[4] "\"gfdlesm2g_45Fall_1020004\", \"gfdlesm2m_45Fall_1020004\", \"hadgem2cc_45Fall_1020004\", "
[5] "\"hadgem2es_45Fall_1020004\", \"hist_Fall_1020004\", \"inmcm4_45Fall_1020004\", "
[6] "\"ipslcm5_alr_45Fall_1020004\", \"ipslcm5_blr_45Fall_1020004\", \"ipslcm5amr_45Fall_1020004\", "
[7] "\"miroc5_45Fall_1020004\", \"mirocesm_45Fall_1020004\", \"mirocesmchem_45Fall_1020004\", "
[8] "\"mricgcm3_45Fall_1020004\", \"noresm1m_45Fall_1020004\"), class = \"factor\"), "
[9] " YEAR = 1961:1963, RO_MM = c(112, 243.7, 233.3)), row.names = c(NA, "
[10] "3L), class = \"data.frame\")"
I would appreciate getting help structuring the data so that I can bring it into ggplot2 and how to make a graph with ggplot2, and explanations would be especially helpful. Thanks.



