I am trying to plot a time vs temperature graph in ggplot. My data frame looks something like this:
Time Temperature
1 07-10-2021 22:00 99.59
2 08-10-2021 02:00 101.50
3 08-10-2021 06:00 101.30
4 08-10-2021 10:00 100.40
5 08-10-2021 14:00 99.80
6 08-10-2021 18:00 100.69
7 08-10-2021 19:00 98.90
8 08-10-2021 20:00 97.50
Running the following code, I am getting the desired results, but the x-axis tick mark labels look very cluttered. I just want to show the time in 24 hr format and not the respective date.
library(ggplot2)
library(ggthemes)
data <- read.csv(file.choose())
plot <- ggplot(data, aes(Time, Temperature, group = 1)) +
geom_point() +
geom_line(size = 1.5, color = "magenta") +
labs(x = "\nTime",
y = "Temperature in fahrenheit\n")+
scale_y_continuous(breaks = c(96,97,98,99,100,101,102,103),limits = c(96, 104))+
geom_text(aes(label = Temperature), color = "white", vjust = -1.5)
plot + theme(
plot.margin = margin(2,2,2,2, unit = "cm"),
panel.background = element_rect(fill = "black", color = "gray20"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "gray30"),
panel.grid = element_line(color = "gray30"),
axis.title = element_text(color = "white", size = rel(1.5)),
axis.text = element_text(face = "bold", color = "white")
)
I want the code to be fully reproducible so that one could enter the time in 24 hr format and the respective temperature in CSV file, import, run and get access to their plots, so I don't want to explicitly use a string as labels.