I am trying to replace the x axis of a histogram with its month, the data looks similar to:
library(tidyverse)
library(lubridate)
library(okcupiddata) # the example data
df <- profiles %>% as_tibble() %>%
select(last_online) %>%
mutate(month = month(last_online, label = TRUE, abbr = FALSE),
day = yday(last_online))
# A tibble: 59,946 x 3
last_online month day
<dttm> <dbl> <dbl>
1 2012-06-28 20:30:00 June 180
2 2012-06-29 21:41:00 June 181
3 2012-06-27 09:10:00 June 179
4 2012-06-28 14:22:00 June 180
5 2012-06-27 21:26:00 June 179
now I want to create a histogram with the days of the year
df %>%
ggplot(aes(x = day, fill = ..count..)) +
geom_histogram(bins = 365) +
scale_y_log10()
I want to replace the day
-axis with it assigned month
variable. I tried to use scale_x_discrete(labels = month)
, but this is just deleting the axis.
I assume I need to perform a larger transformation or programming, but I hope there is already a function that can quickly be applied.
I ultimately want to create a radial plot (adding + coord_polar()
) with the month as a break, similar to this: