Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- output:
- pdf_document
- ---
- # This is our first autogenerated report
- > Here we collect data from Kimono Labs API and produce autogenerated minireport.
- Here you can see activity on publishing news on [RIA Lenta](http://ria.ru/lenta).
- ```{r, include=FALSE}
- api.name <- '1xl232p8'
- api.key <- 'DTndIua4tfpz5kxITOILI6FvmGV8xw9g'
- Sys.setlocale(category = "LC_ALL", locale = "C")
- library(RCurl)
- library(rjson)
- library(ggplot2)
- library(RColorBrewer)
- ```
- ```{r, echo=FALSE}
- json.url <- paste0('https://www.kimonolabs.com/api/', api.name, '?apikey=', api.key)
- json.file <- getURL(json.url, .encoding = 'UTF-8',
- .opts = list(ssl.verifypeer = FALSE))
- json.data <- fromJSON(json.file)
- df <- data.frame()
- for(i in 1:json.data$version){
- csv.url <- paste0('https://www.kimonolabs.com/api/csv/', i, '/', api.name, '?apikey=', api.key)
- csv.file <- getURL(csv.url, .encoding = 'UTF-8', .opts = list(ssl.verifypeer = FALSE))
- csv.rows <- read.csv(textConnection(csv.file), skip=1)
- df <- rbind(df, csv.rows)
- }
- df <- unique(df)
- df$timestamp <- strptime(as.character(df$timestamp), format = '%H:%M %d.%m.%Y')
- df$hour <- df$timestamp$hour
- df$day <- strftime(df$timestamp, format='%d %b')
- df <- aggregate(df, by = list(df$day, df$hour), FUN = length)
- df <- df[, 1:3]
- names(df) <- c('Date', 'Hour', 'Amount')
- specPal <- colorRampPalette(rev(brewer.pal(11, "Spectral")))
- plot <- ggplot(df, aes(x = Hour, y = Date, fill = Amount))
- plot <- plot + geom_tile()
- plot <- plot + scale_fill_gradientn(guide="colourbar", colours = specPal(100), guide_legend(title="Activity"))
- plot <- plot + scale_x_discrete("Hour", limits=0:22, labels=0:23)
- plot <- plot + scale_y_discrete("Day")
- plot <- plot + coord_equal()
- plot <- plot + theme_bw()
- plot <- plot + theme(legend.position="bottom", legend.background = element_rect(colour = "grey"))
- plot <- plot + ggtitle(expression("Publication frequency"))
- print(plot)
- ```
- ## Other abilities
- ### Use lists:
- * Item 1
- * Item 2
- * etc.
- ### Or multiple headers:
- #### Level-4 header
- ### Math is also possible:
- $EngagementRate = 100 \times \frac{likes + shares + comments}{Followers} (\%)$
- ## Conclusion
- Use R and have fun.
Add Comment
Please, Sign In to add comment