0

I have a database and I need to graph dates in R(Rstudio) It is like:

Name    01/01/2018  01/02/2018  01/03/2018  ....

Adam       0            4            3
Adler      1            3            5
Alvin      0            5            9

How can I graph the evolution in Adler's data in R? Thank you

Cami
  • 1
  • 4
    How about transposing the data to make time as a column and then plot the Adam column as a time-series? – Prasanna S Apr 17 '20 at 00:12
  • [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that folks can help with. That includes the code you have so far, and a clear sense of what you're trying to do. It's unclear now how exactly you want to plot this—bar chart? line chart? What packages are you using? – camille Apr 17 '20 at 00:35

1 Answers1

1

Here's a tidy version:

dat <- read.table(header = TRUE, stringsAsFactors = FALSE, check.names = FALSE, text = "
Name    01/01/2018  01/02/2018  01/03/2018
Adam       0            4            3
Adler      1            3            5
Alvin      0            5            9")

library(dplyr)
library(tidyr)
library(ggplot2)
as_tibble(dat) %>%
  pivot_longer(-Name, names_to = "Date") %>%
  mutate(Date = as.Date(Date, format = "%m/%d/%Y")) %>%
  ggplot(., aes(Date, value, color = Name)) +
  geom_line()

sample ggplot2

r2evans
  • 141,215
  • 6
  • 77
  • 149