Commit 2837c443 authored by numeroteca's avatar numeroteca

allow bind and process of multiple raw json + add covid19 SP, AR, BR files

parent 2c82298f
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
......@@ -5,9 +5,31 @@ library(gsubfn)
# Load data -------------------------------------------------
# dataorigen <- fromJSON(file="raw.json")
dataorigen <- fromJSON(file="raw-2newspapers.json")
# dataorigen <- fromJSON(file="raw-2newspapers.json")
# dataorigen <- fromJSON(file="raw-frame.json")
dataorigen <- fromJSON(file="data/covid19/spain.json")
dataorigen2 <- fromJSON(file="data/covid19/argentina.json")
dataorigen3 <- fromJSON(file="data/covid19/brasil.json")
# process 2 or more json files ------------------
# process data contained in json -------------------------------------------------
# images
images <- rbind(dataorigen$images,dataorigen2$images,dataorigen3$images)
images <- lapply(images, function(x) {
x[sapply(x, is.null)] <- NA
unlist(x)
})
pox_img <- as.data.frame(do.call("rbind", images))
# areas
areas <- rbind(dataorigen$areas,dataorigen2$areas,dataorigen3$areas)
areas <- lapply(areas, function(x) {
x[sapply(x, is.null)] <- NA
unlist(x)
})
pox <- as.data.frame(do.call("rbind", areas))
# process data contained in one json file -------------------------------------------------
# images
images <- dataorigen$images
images <- lapply(images, function(x) {
......@@ -24,6 +46,8 @@ areas <- lapply(areas, function(x) {
})
pox <- as.data.frame(do.call("rbind", areas))
# Continue processing ------------
# create widh and height of images
pox_img$w <- as.numeric(strapplyc( as.character(pox_img$image_size), "([0-9]*)x[0-9]*", simplify = TRUE))
pox_img$h <- as.numeric(strapplyc( as.character(pox_img$image_size), "[0-9]x([0-9]*)", simplify = TRUE))
......@@ -56,16 +80,26 @@ pox$area_p <- round(pox$area / pox$img_area *100, digits = 1)
# pox$width <- pox$area_x2 - pox$area_x1
# pox$height <- pox$area_y2 - pox$area_y1
pox$date <- as.Date(pox$publication_date)
pox$date.short <- substr(pox$publication_date,7,10)
# Plot thread in grid format -------------------------------------------------------------------
ggplot(pox)+
png(filename=paste("img/covid/spain-argentina-brasil_01.png", sep = ""),width = 1500,height = 300)
# pox %>% filter (media_country != "Brasil") %>%
pox %>%
ggplot()+
# annotate("rect",xmin = 5, xmax = 500, ymin = 900, ymax = 100) +
# TODO> can not use area_y2 cause it has wrong data
geom_rect(aes(xmin = area_x1, ymin = area_y1, xmax = area_x2 , ymax = area_y1 + area_height, fill=code_text), alpha=1) +
scale_fill_manual(values=c("orange","violet","blue","red","grey")) +
# for colors
# geom_rect(aes(xmin = area_x1, ymin = area_y1, xmax = area_x2 , ymax = area_y1 + area_height, fill=code_text), alpha=1) +
# merge all the codes in one
geom_rect(aes(xmin = area_x1, ymin = area_y1, xmax = area_x2 , ymax = area_y1 + area_height, fill=media_country), alpha=1) +
# scale_fill_manual(values=c("orange","violet","blue","red","grey")) +
# scale_fill_manual(values=c("orange","violet","blue","red","grey")) +
scale_y_reverse() +
facet_grid(media_name~publication_date) +
facet_grid(media_name~date.short) +
coord_fixed() +
theme_minimal(base_family = "Roboto Condensed",base_size = 14) +
theme_minimal(base_family = "Roboto Condensed",base_size = 12) +
theme(
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
......@@ -75,6 +109,6 @@ ggplot(pox)+
panel.background = element_rect(fill = '#EDEDED', colour = '#FFFFFF')
) +
labs(
fill="leyenda"
fill="países"
)
dev.off()
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment