0

I am trying to plot time-series data logged every hour in R. I want to plot Temp over time with my x-axis interval monthly. Currently plotting Temp against log number (61, 62, etc) and having trouble switching the x-axis to month.

`library(readr)
Apex_Log_Data <- read_csv("Aquaria/Apex Log Data.csv")
colnames(Apex_Log_Data)[16] <- "Salx2"
Apex_Log_Data[25] <- NULL
par(mfrow=c(2,1))
par(mar=c(4,2,1,1))
apex <- subset(Apex_Log_Data, Date!="NA")
plot(apex$Tmp, type = "l", ylim = c(25.5, 27.5), xlab = NA, ylab = NA)
  • 2
    What plotting code did you try exactly? Also, it's better to share data in a [reproducible format](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). So we can copy/paste into R for testing. Are there really colons in your column names? – MrFlick Oct 12 '18 at 15:51
  • Sorry, I'm new to SO so I'm working on sharing the data. But no, there are no colons in the column names. They are "Date", "Time", "Tmp" respectively. –  Oct 12 '18 at 18:17

1 Answers1

0

Try this solution using lubridate for easy date handling, and ggplot() for very flexible plotting:

# example data
apex <- data.frame(ID = 60:64,
                     Date = c("9/1/18", "9/2/18", "10/1/18", "10/3/18", "11/2/18"),
                     Time = c("10:00:00", "11:00:00", "12:00:00", "1:00:00", "2:00:00"),
                     Tmp = c(27, 26.9, 26.9, 26.8, 26.8))



library(ggplot2)
library(lubridate)

ggplot(apex) +
    geom_line(aes(x = mdy(Date), y = Tmp)) +
    ylim(c(25.5, 27.5)) +
    labs(x = "", y = "")

enter image description here

HAVB
  • 1,858
  • 1
  • 22
  • 37