Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
-ADD: Function for removing first NA rows
Browse files Browse the repository at this point in the history
  • Loading branch information
Super-T02 committed Dec 8, 2022
1 parent 28af618 commit b27afc9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"r.lsp.diagnostics": false,
}
30 changes: 26 additions & 4 deletions open-data-berlin-monythly/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,25 @@ generateData <- function(months, dataPage, mode = "pi"){
}
return(vals)
}

# Removes rows with the NA for the months before the first value (if there are no visits)
remove_rows <- function(frame) {
removed_row <- c()
finished = FALSE
for (row in row.names(frame)) {
if(!finished & frame[row,'variable'] == "Visits") {

if(any(is.na(frame[row, 'value']))){
removed_row <- c(removed_row, frame[row, 'month'])
} else {
finished = TRUE
}

}
}

return(removed_row)
}

# Function for chart: It will display a dodged bar chart for visits and page impressions
fun_bar_chart <- function(data_enr_temp, page) {
Expand All @@ -57,17 +75,21 @@ fun_bar_chart <- function(data_enr_temp, page) {
page_data['Visits'] <- generateData(page_data$month, data_enr_temp, "v")
page_data['Page impressions - visits'] <- page_data['Impressions'] - page_data['Visits']

# Remove rows with na
#page_data <- na.omit(page_data)

# Melt the data
melted <- melt(page_data[,c("month", c("Page impressions - visits", "Visits"))], id="month")

# Remove the rows until the first value
remove_rows <- remove_rows(melted)
if(!is.null(remove_rows)){
melted <- melted[-which(melted$month %in% remove_rows), ]
}

# View(melted)
title <- paste("Page impressions und visits von", page, "pro Monat", sep = " ")
# Make plot
plot <- ggplot(melted, aes(month, value, fill = variable, label = value)) +
geom_col() +
geom_text( size = 3, position = position_stack( vjust = 0.5 ), color = "white") +
geom_text(size = 3, position = position_stack( vjust = 0.5 ), color = "white", check_overlap=TRUE) +
ggtitle(title) +
ylab("Anzahl") + xlab("Monat") +
scale_fill_manual(values=c("#824f8c", "#e64823"), labels=c('Page impressions - visits', 'Visits'))+
Expand Down

0 comments on commit b27afc9

Please sign in to comment.