I have two tibbles that have the same number and names of columns. I want to plot the two cfs
columns on the same pair of axes, using the site_nbr
as the variable to set the color of each ggplot2 geom_line()
. I present what I've
tried (and the two tibbles) and want to learn:
- How to use
bind_rows()
to create a single tibble from the two separate ones. - How to plot the
cfs
column values for eachsite_nbr
on the same axes pair.
Trying to combine the two tibbles using bind_rows()
fails:
> sal_alb_disc_1988 <- bind_rows(sal_disc_1988, alb_disc_1988)
Error: Can't combine `..1$cfs` <character> and `..2$cfs` <double>.
Run `rlang::last_error()` to see where the error occurred.
> rlang::last_error()
<error/vctrs_error_incompatible_type>
Can't combine `..1$cfs` <character> and `..2$cfs` <double>.
Backtrace:
1. dplyr::bind_rows(sal_disc_1988, alb_disc_1988)
2. vctrs::vec_rbind(!!!dots, .names_to = .id)
4. vctrs::vec_default_ptype2(...)
5. vctrs::stop_incompatible_type(...)
6. vctrs:::stop_incompatible(...)
7. vctrs:::stop_vctrs(...)
And I don't understand the backtrace.
I've found examples of plotting two lines on the same axes, but they all use two columns in the same tibble to do this, not two sets of rows in the same tibble.
The dput()
outputs for the two tibbles follow:
> dput(sal_disc_1988)
structure(list(site_nbr = c("14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720", "14211720", "14211720", "14211720", "14211720",
"14211720", "14211720"), year = c(1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L), mon = c(10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L), day = c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), hr = c(0L, 0L,
0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L,
5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L,
8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L,
10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L,
13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 15L,
15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L,
17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 19L, 19L,
19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L,
21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L,
23L), min = c(10L, 20L, 30L, 40L, 50L, 0L, 10L, 20L, 30L, 40L,
50L, 0L, 10L, 20L, 30L, 40L, 50L, 0L, 10L, 20L, 30L, 40L, 50L,
0L, 10L, 20L, 30L, 40L, 50L, 0L, 10L, 20L, 30L, 40L, 50L, 0L,
10L, 20L, 30L, 40L, 50L, 0L, 10L, 20L, 30L, 40L, 50L, 0L, 10L,
20L, 30L, 40L, 50L, 0L, 10L, 20L, 30L, 40L, 50L, 0L, 10L, 20L,
30L, 40L, 50L, 0L, 10L, 20L, 30L, 40L, 50L, 0L, 10L, 20L, 30L,
40L, 50L, 0L, 10L, 20L, 30L, 40L, 50L, 0L, 10L, 20L, 30L, 40L,
50L, 0L, 10L, 20L, 30L, 40L, 50L, 0L, 10L, 20L, 30L, 40L, 50L,
0L, 10L, 20L, 30L, 40L, 50L, 0L, 10L, 20L, 30L, 40L, 50L, 0L,
10L, 20L, 30L, 40L, 50L, 0L, 10L, 20L, 30L, 40L, 50L, 0L, 10L,
20L, 30L, 40L, 50L, 0L, 10L, 20L, 30L, 40L, 50L, 0L, 10L, 20L,
30L, 40L, 50L), tz = c("PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT"), cfs = c(16800, 16800, 17300, 18200, 18100, 18400,
18700, 19200, 19200, 18900, 18800, 18800, 18800, 18800, 18100,
18100, 18100, 18100, 17800, 17400, 17400, 17400, 17700, 17400,
17300, 17300, 17600, 17800, 17800, 18100, 16600, 16900, 16600,
15700, 15700, 15100, 14300, 13700, 12900, 12000, 10900, 9810,
8690, 7010, 5620, 4220, 2820, 1690, 283, -1130, -2280, -2570,
-2570, -2300, -1440, -865, 0, 1160, 0, 4640, 6390, 0, 0, 15100,
16200, 0, 0, 0, 0, 0, 20400, 19500, 18900, 17700, 16600, 15700,
15400, 15100, 14800, 14500, 14800, 0, 0, 0, 17300, 17000, 17800,
18600, 18000, 18900, 18500, 18200, 17700, 17900, 16800, 17300,
16500, 15900, 14800, 14500, 13700, 12000, 10600, 8660, 7280,
3930, 563, -2820, -5670, -9110, -1200, -1440, -1650, -1800, -1810,
-1680, -1600, -1390, -1070, -7480, -4500, -1510, 1510, 4530,
6350, 7860, 9990, 12100, 13900, 15400, 17200, 18700, 21000, 23100,
24200, 24800, 24700, 24100, 23100, 22800, 21500, 20600, 19700
), sampdt = structure(c(591667800, 591668400, 591669000, 591669600,
591670200, 591670800, 591671400, 591672000, 591672600, 591673200,
591673800, 591674400, 591675000, 591675600, 591676200, 591676800,
591677400, 591678000, 591678600, 591679200, 591679800, 591680400,
591681000, 591681600, 591682200, 591682800, 591683400, 591684000,
591684600, 591685200, 591685800, 591686400, 591687000, 591687600,
591688200, 591688800, 591689400, 591690000, 591690600, 591691200,
591691800, 591692400, 591693000, 591693600, 591694200, 591694800,
591695400, 591696000, 591696600, 591697200, 591697800, 591698400,
591699000, 591699600, 591700200, 591700800, 591701400, 591702000,
591702600, 591703200, 591703800, 591704400, 591705000, 591705600,
591706200, 591706800, 591707400, 591708000, 591708600, 591709200,
591709800, 591710400, 591711000, 591711600, 591712200, 591712800,
591713400, 591714000, 591714600, 591715200, 591715800, 591716400,
591717000, 591717600, 591718200, 591718800, 591719400, 591720000,
591720600, 591721200, 591721800, 591722400, 591723000, 591723600,
591724200, 591724800, 591725400, 591726000, 591726600, 591727200,
591727800, 591728400, 591729000, 591729600, 591730200, 591730800,
591731400, 591732000, 591732600, 591733200, 591733800, 591734400,
591735000, 591735600, 591736200, 591736800, 591737400, 591738000,
591738600, 591739200, 591739800, 591740400, 591741000, 591741600,
591742200, 591742800, 591743400, 591744000, 591744600, 591745200,
591745800, 591746400, 591747000, 591747600, 591748200, 591748800,
591749400, 591750000, 591750600, 591751200, 591751800, 591752400,
591753000), tzone = "UTC", class = c("POSIXct", "POSIXt"))), row.names = c(NA,
-143L), class = c("tbl_df", "tbl", "data.frame"))
> dput(sal_disc_1988)
structure(list(site_nbr = c("14191000", "14191000", "14191000",
"14191000", "14191000", "14191000", "14191000", "14191000", "14191000",
"14191000", "14191000", "14191000", "14191000", "14191000", "14191000",
"14191000", "14191000", "14191000", "14191000", "14191000", "14191000",
"14191000", "14191000", "14191000", "14191000", "14191000", "14191000",
"14191000", "14191000", "14191000", "14191000", "14191000", "14191000",
"14191000", "14191000", "14191000", "14191000", "14191000", "14191000",
"14191000", "14191000", "14191000", "14191000", "14191000", "14191000",
"14191000", "14191000"), year = c(1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L), mon = c(10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L), day = c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), hr = c(0L, 1L, 1L, 2L,
2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L,
10L, 11L, 11L, 12L, 12L, 13L, 13L, 14L, 14L, 15L, 15L, 16L, 16L,
17L, 17L, 18L, 18L, 19L, 19L, 20L, 20L, 21L, 21L, 22L, 22L, 23L,
23L), min = c(30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L,
0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L,
0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L,
0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L), tz = c("PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT"), cfs = c("9430",
"9400", "9400", "9400", "9400", "9370", "9370", "9370", "9370",
"9370", "9370", "9370", "9370", "9370", "9370", "9370", "9400",
"9400", "9400", "9430", "9460", "9460", "9490", "9490", "9490",
"9550", "9550", "9550", "9550", "9550", "9550", "9520", "9520",
"9520", "9490", "9460", "9460", "9430", "9430", "9430", "9400",
"9370", "9370", "9370", "9370", "9370", "9340"), sampdt = structure(c(591669000,
591670800, 591672600, 591674400, 591676200, 591678000, 591679800,
591681600, 591683400, 591685200, 591687000, 591688800, 591690600,
591692400, 591694200, 591696000, 591697800, 591699600, 591701400,
591703200, 591705000, 591706800, 591708600, 591710400, 591712200,
591714000, 591715800, 591717600, 591719400, 591721200, 591723000,
591724800, 591726600, 591728400, 591730200, 591732000, 591733800,
591735600, 591737400, 591739200, 591741000, 591742800, 591744600,
591746400, 591748200, 591750000, 591751800), tzone = "UTC", class = c("POSIXct",
"POSIXt"))), row.names = c(NA, -47L), class = c("tbl_df", "tbl",
"data.frame"))
and
> dput(alb_disc_1988)
structure(list(site_nbr = c("14174000", "14174000", "14174000",
"14174000", "14174000", "14174000", "14174000", "14174000", "14174000",
"14174000", "14174000", "14174000", "14174000", "14174000", "14174000",
"14174000", "14174000", "14174000", "14174000", "14174000", "14174000",
"14174000", "14174000", "14174000", "14174000", "14174000", "14174000",
"14174000", "14174000", "14174000", "14174000", "14174000", "14174000",
"14174000", "14174000", "14174000", "14174000", "14174000", "14174000",
"14174000", "14174000", "14174000", "14174000", "14174000", "14174000",
"14174000", "14174000"), year = c(1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L), mon = c(10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L), day = c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), hr = c(0L, 1L, 1L, 2L,
2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L,
10L, 11L, 11L, 12L, 12L, 13L, 13L, 14L, 14L, 15L, 15L, 16L, 16L,
17L, 17L, 18L, 18L, 19L, 19L, 20L, 20L, 21L, 21L, 22L, 22L, 23L,
23L), min = c(30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L,
0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L,
0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L,
0L, 30L, 0L, 30L, 0L, 30L, 0L, 30L), tz = c("PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT",
"PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT", "PDT"), cfs = c(6400,
6400, 6400, 6400, 6380, 6380, 6380, 6380, 6380, 6380, 6380, 6380,
6380, 6380, 6370, 6370, 6370, 6370, 6370, 6350, 6350, 6330, 6310,
6310, 6310, 6310, 6290, 6270, 6270, 6250, 6270, 6250, 6250, 6250,
6230, 6230, 6230, 6230, 6230, 6220, 6220, 6220, 6230, 6220, 6220,
6220, 6220), sampdt = structure(c(591669000, 591670800, 591672600,
591674400, 591676200, 591678000, 591679800, 591681600, 591683400,
591685200, 591687000, 591688800, 591690600, 591692400, 591694200,
591696000, 591697800, 591699600, 591701400, 591703200, 591705000,
591706800, 591708600, 591710400, 591712200, 591714000, 591715800,
591717600, 591719400, 591721200, 591723000, 591724800, 591726600,
591728400, 591730200, 591732000, 591733800, 591735600, 591737400,
591739200, 591741000, 591742800, 591744600, 591746400, 591748200,
591750000, 591751800), tzone = "UTC", class = c("POSIXct", "POSIXt"
))), row.names = c(NA, -47L), class = c("tbl_df", "tbl", "data.frame"
))
If more information is needed, then I'll provide it.
TIA, Rich
CodePudding user response:
In the alb_disc_1988
dataframe, it looks like cfs
is a character; whereas, in the other dataframe (sal_disc_1988
), it is double. Columns must have the same data type to bind_rows
. But you can mutate
the data type while you bind rows. Or you can also use mutate
to change alb_disc_1988
before using bind_rows
.
library(tidyverse)
sal_alb_disc_1988 <- dplyr::bind_rows(mutate(sal_disc_1988,
cfs = as.numeric(cfs)),
mutate(alb_disc_1988, cfs = as.numeric(cfs)))
If you want to fix alb_disc_1988
before binding, then you could use dplyr
or base R. Then, you would run the bind_rows
as normal.
alb_disc_1988 <- alb_disc_1988 %>%
mutate(cfs = as.numeric(cfs))
# Or using base R
alb_disc_1988$cfs <- as.numeric(alb_disc_1988$cfs)
sal_alb_disc_1988 <- dplyr::bind_rows(sal_disc_1988, alb_disc_1988)
For plotting, I'm assuming you want to plot by time. If so, then you could do something like this. Site number 14174000 changes very little in comparison to the other site, which is the reason for the seemingly flat line.
sal_alb_disc_1988 %>%
ggplot(aes(x = sampdt, y = cfs, color = site_nbr))
geom_line()
Output
CodePudding user response:
Something like this?
library(tidyverse)
# How to use `bind_rows` to get one tibble
single_tibble <- bind_rows(sal_disc_1988, alb_disc_1988)
# How to plot with `ggplot`
ggplot(single_tibble, aes(x=sampdt, y=cfs, color=site_nbr))
geom_line()
CodePudding user response:
Column sal_disc_1988$cfs
is a character and alb_disc_1988$cfs
is numeric, that is why bind_rows()
is not working. Try
library (tidyverse)
df <- sal_disc_1988 %>%
mutate(cfs=as.numeric(cfs)) %>%
bind_rows(alb_disc_1988)
For plotting, just
df %>%
ggplot(aes(x = sampdt, y = cfs, color = site_nbr))
geom_line()