-1

I have an experiment which lasts from 2018/06/28 08:00:00 to 2018/06/29 07:00:00 (24 hours). Since I had more observations per hour at different minutes, but I needed to plot the hourly mean I cutted out minutes and seconds.

Now my time data is in following form: 2018/06/28 08, 2018/06/28 09, 2018/06/28 10 ... 2018/06/29 07.

If I plot the values now they are in the right order, but the x axis doesn't look good, because the x label is too long. If I change the date format with the hour only, ggplot is mixing my data because it orders the hours 00, 01, 02... But my experiment starts on 08 and ends at 07.

How to solve it?

Thanks a lot

Rémi Coulaud
  • 1,684
  • 1
  • 8
  • 19
  • [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 a sample of data, all necessary code, and a clear explanation of what you're trying to do and what hasn't worked. You're telling us you need to change a plot, but we can't see anything – camille Dec 12 '19 at 18:25
  • If the answer gives you the solution, you can validate it. Thanks. – Rémi Coulaud Dec 22 '19 at 09:47

1 Answers1

0

I agree with the comments, there is a clear lack of information. But, I hope you use ggplot and that your problem is only a problem of displaying nice x args ticks like in : Changing x axis tick labels in R using ggplot2.

So I made a simple exemple :

set.seed(123)
n <- 10
df <- data.frame(x = as.factor(paste("xargsfartoolonghowIwilldeal", 1:n)),
                 y = rnorm(n))

ggplot(df, aes(x = x, y = y)) +
  geom_point() + 
  theme_classic()

enter image description here

You can just kill all x ticks :

ggplot(df, aes(x = x, y = y)) +
  geom_point() + 
  theme_classic() +
  theme(axis.text.x = element_blank())

You can change x ticks arguments :

ggplot(df, aes(x = x, y = y)) +
  geom_point() +
  scale_x_discrete(labels = paste("T", 1:n)) +
  theme_classic()

enter image description here

You can modify the orientation/aspect of the ticks :

ggplot(df, aes(x = x, y = y)) +
  geom_point() + 
  theme_classic() +
  theme(axis.text.x = element_text(size = 5, angle = 45, hjust = 1))

enter image description here

I hope it helps.

Community
  • 1
  • 1
Rémi Coulaud
  • 1,684
  • 1
  • 8
  • 19