2

This is a relatively straightforward question, however, I was unable to find an answer. Likewise, I am not used to posting at Stackoverflow so I apologise for any kind of errors.

I currently have a Multiplot Facet that displays the variation in animal activity (Y) and day length on a seasonal level (in this case, two seasons).

enter image description here

As you see on the X axis, there are numbers such as 0.45, 0.47, etc. These represent time in numeric form. The issue is, is that I would like to convert 0.45 and etc to hours (it should be noted that they are not represented as dates). That is, 0.45 should represent 10, 0.47 should represent 10.2 etc. While I attempted to manually do this in excel...the scatter plots are well..not very scattered when plotting them. That is, I simply converted 10:02:00 to 10.2 (therefore, they do not represent actual dates in R)

enter image description here

Is there a way to either 1. manually change the numeric daylength (i.e. 0.45) to the hours that they represent? 2. Shorten the tick marks for the actual hours for both facets so that they do not seemed as scattered?

Likewise, is all of this possible while keeping both facets in place?

Here is the script that I use for the plot:

ii$season = factor(ii$season, levels = c("Winter","Summer"))

ii <- ii%>% 

mutate(season = ifelse(month2 %in% c( 6,7, 8), "Winter",

ifelse(month2 %in% c(12,1,2), "Summer","Error")))

Plot <- ggplot(ii, aes(daylength, newavx2)) +

geom_point() + geom_smooth()+

ggtitle("Activity and Daylength by Season") +

xlab("Daylength") + ylab("Activity") +

theme(plot.title = element_text(lineheight=.8, face="bold",size = 20)) +

theme(text = element_text(size=18))

Plot + facet_grid(.~season, scales = "free_x") +

theme(strip.background = element_blank())

It should be noted that for the second plot, the variable daylength is simply replaced by 'hours' Thank you so much for your help

Uwe
  • 41,420
  • 11
  • 90
  • 134
  • 2
    Just use the `breaks` and `labels` arguments of `scale_x_continuous` to set the breaks wherever you want and the labels whatever you want. The duplicate has a discrete x-axis, you have a continuous x-axis, so you will need to change `scale_x_discrete` to `scale_x_continuous`, but everything else should be the same. – Gregor Thomas Dec 31 '16 at 17:26
  • Your other option would be to add a new data column, it sounds like your transformation would be `ii$x = ii$daylength - 0.45 + 10`... – Gregor Thomas Dec 31 '16 at 17:29
  • Hey, thank you so much for responding. I greatly appreciate it. I do not know why, but I am having a very difficult time figuring out the right way to change scale_x_discrete to scale_x_continuous (while keeping everything else the same) and I am not really sure where to put it. For clarity, would you be able to provide a quick example regarding where and what to put into the code? I aplogise for such a trivial question and happy new year! – Redskies421 Jan 02 '17 at 17:59
  • Oh, looking over your question I completely misunderstood. You mean that the decimals are literally minutes! So 0.45 means 10:45. You should just covert them to strings and then to a real date-time class. Just pick a date, it doesn't matter what day, and use a datetime class built for this use case. I had though you simply wanted different labels... – Gregor Thomas Jan 02 '17 at 21:03
  • thank you so much for your response and I apologise about the phrasing! – Redskies421 Jan 04 '17 at 22:44
  • Please, can you show how your `daylength` data looked in the original data (Excel file?) before you manipulated it? – Uwe Jan 06 '17 at 09:12

0 Answers0