Last active
March 26, 2020 11:57
-
-
Save therohk/cceef36656cfdfa81b0773e52aa30007 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plot_slice_freq = function(dfin, start, stend, include=c(), stem_flag=TRUE, floor_unit="halfyear", plot_name="_") { | |
# ---- publish-date-ungram-hertz | |
ungram_hz_inc <- dfin %>% | |
subset(select=c(ungram,publish_date)) %>% | |
mutate(Date = as.Date(substr(publish_date,1,8), format="%Y%m%d")) %>% | |
filter(Date>=start & Date<=stend) | |
if(stem_flag) { | |
ungram_hz_inc$ungram <- wordStem(ungram_hz_inc$ungram, language="english") | |
include <- wordStem(include, language="english") | |
} | |
ungram_hz_inc <- ungram_hz_inc %>% | |
filter(ungram %in% include) %>% | |
mutate(time_floor = floor_date(Date, unit=floor_unit)) %>% | |
group_by(time_floor, ungram) %>% | |
summarise(count=n()) | |
ungram_hz_inc <- ungram_hz_inc %>% | |
ungroup() %>% | |
complete(nesting(ungram), time_floor) | |
ungram_hz_inc[is.na(ungram_hz_inc$count), "count"]<-0 | |
ungram_hz_plot <- data.frame(ungram_hz_inc) | |
ungram_hz_plot$unifctr <- factor(ungram_hz_plot$ungram, levels=include) | |
plot_title <- paste(plot_name, "ungram hertz", start, "unto", stend, "slby", floor_unit,"ly") | |
plot_ly(ungram_hz_plot, x = ~time_floor, y = ~log2(count), split = ~unifctr, type = 'scatter', mode = 'lines') %>% | |
layout(title = plot_title, xaxis = list(rangeslider = list(type = "date")), yaxis = list(title = "freq-log2")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment